Esempio n. 1
0
        private void listViewAlgorythm_SelectedIndexChanged(object sender, EventArgs e)
        {
            try
            {
                if (listViewAlgorythm.SelectedItems.Count == 1)
                {
                    comboBoxProperityName.Items.Clear();
                    listViewAlgorithmProperity.Items.Clear();
                    int index = listViewAlgorythm.SelectedItems[0].Index;
                    List <KeyValuePair <string, string> > properities = m_lAlgorithmsList[index].GetProperitis();

                    foreach (KeyValuePair <string, string> prop in properities)
                    {
                        ListViewItem it = new ListViewItem(prop.Key);
                        it.SubItems.Add(prop.Value);
                        listViewAlgorithmProperity.Items.Add(it);
                        comboBoxProperityName.Items.Add(prop.Key);
                    }
                }
            }
            catch (Exception ex)
            {
                Cursor.Current = Cursors.Arrow;
                MessageBox.Show(ex.Message + "\n\n Call Stack:\n\n" + ex.StackTrace, "Exception !", MessageBoxButtons.OK, MessageBoxIcon.Error);
                ClInformationSender.SendInformation("EXCEPTION\n" + ex.Message + "\n\n Call Stack:\n\n" + ex.StackTrace, ClInformationSender.eInformationType.eDebugText);
            }
        }
Esempio n. 2
0
 private void sAVEToolStripMenuItem_Click(object sender, EventArgs e)
 {
     // m_lAlgorithmsList
     try
     {
         if (saveFileDialogAlgorithm.ShowDialog() == DialogResult.OK)
         {
             using (TextWriter tw = new StreamWriter(saveFileDialogAlgorithm.FileName, false))
             {
                 foreach (IFaceAlgorithm alg in m_lAlgorithmsList)
                 {
                     tw.WriteLine("Algorithm");
                     tw.WriteLine(alg.GetAlgorithmFullPath());
                     tw.WriteLine(alg.GetProperitis().Count.ToString());
                     foreach (KeyValuePair <string, string> par in alg.GetProperitis())
                     {
                         tw.WriteLine(par.Key + "\t" + par.Value);
                     }
                 }
                 tw.Close();
             }
         }
     }
     catch (Exception ex)
     {
         //Cursor.Current = Cursors.Arrow;
         MessageBox.Show(ex.Message, "Exception !", MessageBoxButtons.OK, MessageBoxIcon.Error);
         ClInformationSender.SendInformation("EXCEPTION\n" + ex.Message + "\n\n Call Stack:\n\n" + ex.StackTrace, ClInformationSender.eInformationType.eDebugText);
     }
 }
Esempio n. 3
0
        public DxForm(string ApplicationName, string ApplicationVersion)
        {
            APPLICATION_NAME    = ApplicationName;
            APPLICATION_VERSION = ApplicationVersion;
#if RENDER_0
            APPLICATION_VERSION += " [version without 3D models rendering]";
#endif

            InitializeComponent();
#if RENDER_1
            Application.AddMessageFilter(new CScrollPanelMessageFilter(this.PanelDirectX)); // neaded to get event about scroll wheal in the panel
            this.PanelDirectX.MouseMove  += new System.Windows.Forms.MouseEventHandler(ClEventSender.getInstance().BroadcastMouseMoveEvent);
            this.PanelDirectX.MouseDown  += new System.Windows.Forms.MouseEventHandler(ClEventSender.getInstance().BroadcastMouseButtonDownEvent);
            this.PanelDirectX.MouseUp    += new System.Windows.Forms.MouseEventHandler(ClEventSender.getInstance().BroadcastMouseButtonUpEvent);
            this.PanelDirectX.MouseWheel += new System.Windows.Forms.MouseEventHandler(ClEventSender.getInstance().BroadcastMouseWheelEvent);
#endif
            ClInformationReciver viewer = new ClInformationReciver(this);
            ClInformationSender.RegisterReceiver(viewer, ClInformationSender.eInformationType.eDebugText);
            ClInformationSender.RegisterReceiver(viewer, ClInformationSender.eInformationType.eError);
            ClInformationSender.RegisterReceiver(viewer, ClInformationSender.eInformationType.eProgress);
            ClInformationSender.RegisterReceiver(viewer, ClInformationSender.eInformationType.eTextInternal);
            ClInformationSender.RegisterReceiver(viewer, ClInformationSender.eInformationType.eTextExternal);
            ClInformationSender.RegisterReceiver(viewer, ClInformationSender.eInformationType.eStartProcessing);
            ClInformationSender.RegisterReceiver(viewer, ClInformationSender.eInformationType.eStopProcessing);
            ClInformationSender.RegisterReceiver(viewer, ClInformationSender.eInformationType.eColorMapChanged);
            ClInformationSender.RegisterReceiver(viewer, ClInformationSender.eInformationType.eNextRecognitionScore);
            ClInformationSender.RegisterReceiver(viewer, ClInformationSender.eInformationType.eWindowInfo);

            this.Text = APPLICATION_NAME + " ver. " + APPLICATION_VERSION;

#if RENDER_1
            ClRender Render = ClRender.getInstance();
            Render.CreateDevice(this.PanelDirectX);

            ClCamera Camera = new ClCamera();   // Create camera object
            Camera.RegisterForEvent(ClEventSender.eEvents.e_MouseMove);
            Camera.RegisterForEvent(ClEventSender.eEvents.e_MouseButtonDown);
            Camera.RegisterForEvent(ClEventSender.eEvents.e_MouseButtonUp);
            Camera.RegisterForEvent(ClEventSender.eEvents.e_MouseWheel);
            Render.SetCamera(Camera);   // Register camera as a render object

            //  Render.AddRenderObj(new ClCoordinateSystem());
#endif
            List <string> fileTypes = Cl3DModel.sm_ListManagedFilesExtensions;
            string        filter    = "";
            string        AllNames  = "All supported types";
            string        AllExt    = "";
            foreach (string type in fileTypes)
            {
                AllExt += "*." + type + ";";
                filter += type.ToUpper() + "|*." + type + "|";
            }
            filter = filter.Remove(filter.Length - 1);
            AllExt = AllExt.Remove(AllExt.Length - 1);
            openFileDialog.Filter = AllNames + "|" + AllExt + "|" + filter;
        }
        public override void MouseButtonDown(object sender, MouseEventArgs e)
        {
            base.MouseButtonDown(sender, e);

            if (m_bRightMouseButtonDown && m_bLeftMouseButtonDown)
            {
                m_fCamUpVectorY *= (-1);
                ClInformationSender.SendInformation("Cam vector is: " + m_fCamUpVectorY.ToString(), ClInformationSender.eInformationType.eDebugText);
            }
        }
Esempio n. 5
0
 private void DxForm_Activated(object sender, EventArgs e)
 {
     try
     {
     }
     catch (Exception ex)
     {
         //Cursor.Current = Cursors.Arrow;
         MessageBox.Show(ex.Message, "Exception !", MessageBoxButtons.OK, MessageBoxIcon.Error);
         ClInformationSender.SendInformation("EXCEPTION\n" + ex.Message + "\n\n Call Stack:\n\n" + ex.StackTrace, ClInformationSender.eInformationType.eDebugText);
     }
 }
Esempio n. 6
0
        public void StartRendering()
        {
            if (m_bRenderScene || m_dDevice == null)
            {
                return;
            }

            m_tRenderingThread          = new System.Threading.Thread(this.RenderScene);
            m_bRenderScene              = true;
            m_tRenderingThread.Priority = System.Threading.ThreadPriority.Lowest;
            m_tRenderingThread.Start();
            ClInformationSender.SendInformation("Rendering ON", ClInformationSender.eInformationType.eTextExternal);
        }
Esempio n. 7
0
        private void lOADToolStripMenuItem_Click(object sender, EventArgs e)
        {
            // m_lAlgorithmsList
            try
            {
                if (openFileDialogAlgorithm.ShowDialog() == DialogResult.OK)
                {
                    using (TextReader tr = new StreamReader(openFileDialogAlgorithm.FileName))
                    {
                        String line = "";
                        while ((line = tr.ReadLine()) != null)
                        {
                            if (line.Equals("Algorithm"))
                            {
                                line = tr.ReadLine();
                                IFaceAlgorithm alg = ClMapObjectAlgorithmBuilder.CreateNewAlgorithm(line);

                                int no = Int32.Parse(tr.ReadLine());
                                for (int i = 0; i < no; i++)
                                {
                                    string InnerLine = tr.ReadLine();
                                    if (InnerLine == null)
                                    {
                                        continue;
                                    }

                                    string[] keyV = InnerLine.Split('\t');
                                    alg.SetProperitis(keyV[0], keyV[1]);
                                }

                                m_lAlgorithmsList.Add(alg);

                                listViewAlgorythm.Items.Add(alg.GetAlgorithmName(), 0);
                            }
                            else
                            {
                                throw new Exception("Unknown tocken");
                            }
                        }
                        tr.Close();
                    }
                }
            }
            catch (Exception ex)
            {
                //Cursor.Current = Cursors.Arrow;
                MessageBox.Show(ex.Message, "Exception !", MessageBoxButtons.OK, MessageBoxIcon.Error);
                ClInformationSender.SendInformation("EXCEPTION\n" + ex.Message + "\n\n Call Stack:\n\n" + ex.StackTrace, ClInformationSender.eInformationType.eDebugText);
            }
        }
        protected override void Algorithm(ref Cl3DModel p_Model)
        {
            string fileName = ClTools.ExtractOryginalFileNameFRGC(p_Model.ModelFileName);

            string expression = "";

            if (!ClTools.ClExpressionFRGC.GetExpression(fileName, out expression))
            {
                throw new Exception("Cannot find Expression for file " + p_Model.ModelFilePath);
            }

            p_Model.ModelExpression = expression;

            ClInformationSender.SendInformation("Model has expression: " + p_Model.ModelExpression, ClInformationSender.eInformationType.eDebugText);
        }
Esempio n. 9
0
 private void DxForm_Resize(object sender, EventArgs e)
 {
     try
     {
         toolStripStatusLabel1.Width    = (int)(this.Width * 0.3);
         toolStripStatusLabel2.Width    = (int)(this.Width * 0.4);
         toolStripStatusLabelLast.Width = (int)(this.Width * 0.1);
         toolStripProgressBar1.Width    = (int)(this.Width * 0.2);
     }
     catch (Exception ex)
     {
         //Cursor.Current = Cursors.Arrow;
         MessageBox.Show(ex.Message, "Exception !", MessageBoxButtons.OK, MessageBoxIcon.Error);
         ClInformationSender.SendInformation("EXCEPTION\n" + ex.Message + "\n\n Call Stack:\n\n" + ex.StackTrace, ClInformationSender.eInformationType.eDebugText);
     }
 }
Esempio n. 10
0
 private void Reset_Click(object sender, EventArgs e)
 {
     try
     {
         listViewAlgorythm.Clear();
         m_lAlgorithmsList.Clear();
         listViewAlgorithmProperity.Items.Clear();
         comboBoxProperityName.Items.Clear();
     }
     catch (Exception ex)
     {
         Cursor.Current = Cursors.Arrow;
         MessageBox.Show(ex.Message + "\n\n Call Stack:\n\n" + ex.StackTrace, "Exception !", MessageBoxButtons.OK, MessageBoxIcon.Error);
         ClInformationSender.SendInformation("EXCEPTION\n" + ex.Message + "\n\n Call Stack:\n\n" + ex.StackTrace, ClInformationSender.eInformationType.eDebugText);
     }
 }
Esempio n. 11
0
 private void toolStripButtonOpenFolder_Click(object sender, EventArgs e)
 {
     try
     {
         if (folderBrowserDialog.ShowDialog() == DialogResult.OK)
         {
             this.Text        = APPLICATION_NAME + " <" + folderBrowserDialog.SelectedPath + ">";
             m_sTestDirectory = folderBrowserDialog.SelectedPath;
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message + "\n\n Call Stack:\n\n" + ex.StackTrace, "Exception !", MessageBoxButtons.OK, MessageBoxIcon.Error);
         ClInformationSender.SendInformation("EXCEPTION\n" + ex.Message + "\n\n Call Stack:\n\n" + ex.StackTrace, ClInformationSender.eInformationType.eDebugText);
     }
 }
Esempio n. 12
0
 public void StopRendering()
 {
     if (m_bRenderScene != false)
     {
         m_bRenderScene = false;
         if (m_tRenderingThread != null)
         {
             while (m_tRenderingThread.IsAlive)
             {
                 //waiting for the end of the thread;
             }
         }
         m_tRenderingThread = null;
         ClInformationSender.SendInformation("Rendering OFF", ClInformationSender.eInformationType.eTextExternal);
     }
 }
Esempio n. 13
0
        private void toolStripButtonStartAlgorithm_Click(object sender, EventArgs e)
        {
            try
            {
                if (ClFasadaPreprocessing.IsPreProcessing())
                {
                    ClFasadaPreprocessing.ResetFasade();
                    return;
                }

                if (m_lAlgorithmsList.Count == 0)
                {
                    MessageBox.Show("Choose PreProcessing Algorithm(s)", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }

                if (m_Model3D == null)
                {
                    if (m_sTestDirectory.Length == 0)
                    {
                        MessageBox.Show("Choose Test Directory", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        return;
                    }
                    FilesExtensionForm form = new FilesExtensionForm(Cl3DModel.sm_ListManagedFilesExtensions);
                    form.ShowDialog();
                    if (form.OutExtensionList.Count == 0)
                    {
                        MessageBox.Show("No files Extension has been chosen", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        return;
                    }
                    Cursor.Current = Cursors.WaitCursor;
                    ClFasadaPreprocessing.RunAlgorithms(m_sTestDirectory, m_lAlgorithmsList, form.OutExtensionList, checkBoxLogging.Checked, checkBoxSubfolders.Checked); // w przyszlosci mozna wybrac formaty ktore chce sie przetwarzac
                }
                else
                {
                    Cursor.Current = Cursors.WaitCursor;
                    ClFasadaPreprocessing.RunAlgorithms(m_Model3D, m_lAlgorithmsList);
                }
            }
            catch (Exception ex)
            {
                Cursor.Current = Cursors.Arrow;
                MessageBox.Show(ex.Message + "\n\n Call Stack:\n\n" + ex.StackTrace, "Exception !", MessageBoxButtons.OK, MessageBoxIcon.Error);
                ClInformationSender.SendInformation("EXCEPTION\n" + ex.Message + "\n\n Call Stack:\n\n" + ex.StackTrace, ClInformationSender.eInformationType.eDebugText);
            }
        }
Esempio n. 14
0
 private void comboBoxProperityName_SelectedIndexChanged(object sender, EventArgs e)
 {
     try
     {
         if (comboBoxProperityName.SelectedIndex != -1)
         {
             int index = comboBoxProperityName.SelectedIndex;
             textBoxProperityValue.Text = listViewAlgorithmProperity.Items[index].SubItems[1].Text;
         }
     }
     catch (Exception ex)
     {
         Cursor.Current = Cursors.Arrow;
         MessageBox.Show(ex.Message + "\n\n Call Stack:\n\n" + ex.StackTrace, "Exception !", MessageBoxButtons.OK, MessageBoxIcon.Error);
         ClInformationSender.SendInformation("EXCEPTION\n" + ex.Message + "\n\n Call Stack:\n\n" + ex.StackTrace, ClInformationSender.eInformationType.eDebugText);
     }
 }
Esempio n. 15
0
 private void changeBackgroundColorToolStripMenuItem_Click(object sender, EventArgs e)
 {
     try
     {
         if (colorDialog.ShowDialog() == DialogResult.OK)
         {
             #if RENDER_1
             ClRender.getInstance().SetBackgroundColor(colorDialog.Color);
             #endif
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message + "\n\n Call Stack:\n\n" + ex.StackTrace, "Exception !", MessageBoxButtons.OK, MessageBoxIcon.Error);
         ClInformationSender.SendInformation("EXCEPTION\n" + ex.Message + "\n\n Call Stack:\n\n" + ex.StackTrace, ClInformationSender.eInformationType.eDebugText);
     }
 }
Esempio n. 16
0
 private void toolStripMenuItemChangeFaceColor_Click(object sender, EventArgs e)
 {
     try
     {
         if (colorDialog.ShowDialog() == DialogResult.OK)
         {
             if (m_Model3D != null)
             {
                 m_Model3D.ResetColor(colorDialog.Color);
             }
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message + "\n\n Call Stack:\n\n" + ex.StackTrace, "Exception !", MessageBoxButtons.OK, MessageBoxIcon.Error);
         ClInformationSender.SendInformation("EXCEPTION\n" + ex.Message + "\n\n Call Stack:\n\n" + ex.StackTrace, ClInformationSender.eInformationType.eDebugText);
     }
 }
Esempio n. 17
0
 private void Delete_Click(object sender, EventArgs e)
 {
     try
     {
         if (listViewAlgorythm.SelectedItems.Count == 1)
         {
             int index = listViewAlgorythm.SelectedItems[0].Index;
             listViewAlgorythm.Items.RemoveAt(index);
             m_lAlgorithmsList.RemoveAt(index);
         }
     }
     catch (Exception ex)
     {
         Cursor.Current = Cursors.Arrow;
         MessageBox.Show(ex.Message + "\n\n Call Stack:\n\n" + ex.StackTrace, "Exception !", MessageBoxButtons.OK, MessageBoxIcon.Error);
         ClInformationSender.SendInformation("EXCEPTION\n" + ex.Message + "\n\n Call Stack:\n\n" + ex.StackTrace, ClInformationSender.eInformationType.eDebugText);
     }
 }
Esempio n. 18
0
        private void DxForm_Deactivate(object sender, EventArgs e)
        {
            try
            {
#if RENDER_1
                if (!ClFasadaPreprocessing.IsPreProcessing())
                {
                    ClRender.getInstance().StopRendering();
                }
#endif
            }
            catch (Exception ex)
            {
                //Cursor.Current = Cursors.Arrow;
                MessageBox.Show(ex.Message, "Exception !", MessageBoxButtons.OK, MessageBoxIcon.Error);
                ClInformationSender.SendInformation("EXCEPTION\n" + ex.Message + "\n\n Call Stack:\n\n" + ex.StackTrace, ClInformationSender.eInformationType.eDebugText);
            }
        }
Esempio n. 19
0
 private void treeViewOperations_DoubleClick(object sender, EventArgs e)
 {
     try
     {
         if (treeViewOperations.SelectedNode != null)
         {
             if (treeViewOperations.SelectedNode.Nodes.Count == 0) // last node so it is algorithm
             {
                 listViewAlgorythm.Items.Add(treeViewOperations.SelectedNode.Text, 0);
                 string algName = treeViewOperations.SelectedNode.FullPath.ToString();
                 m_lAlgorithmsList.Add(ClMapObjectAlgorithmBuilder.CreateNewAlgorithm(algName));
             }
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message + "\n\n Call Stack:\n\n" + ex.StackTrace, "Exception !", MessageBoxButtons.OK, MessageBoxIcon.Error);
         ClInformationSender.SendInformation("EXCEPTION\n" + ex.Message + "\n\n Call Stack:\n\n" + ex.StackTrace, ClInformationSender.eInformationType.eDebugText);
     }
 }
Esempio n. 20
0
        protected override void Algorithm(ref Cl3DModel p_Model)
        {
            Cl3DModel.Cl3DModelPointIterator iter = p_Model.GetIterator();

            if (m_bRandomX)
            {
                Random random = new Random();
                m_fAngleX = (int)random.Next(-45, 45);
            }
            if (m_bRandomY)
            {
                Random random = new Random();
                m_fAngleY = (int)random.Next(-90, 90);
            }
            if (m_bRandomZ)
            {
                Random random = new Random();
                m_fAngleZ = (int)random.Next(-30, 30);
            }

            ClInformationSender.SendInformation("ROTATIONS: X: " + m_fAngleX + " Y: " + m_fAngleY + " Z: " + m_fAngleZ, ClInformationSender.eInformationType.eDebugText);

            while (iter.IsValid())
            {
                float X = iter.X;
                float Y = iter.Y;
                float Z = iter.Z;
                ClTools.RotateXDirection(X, Y, Z, m_fAngleX * (float)(Math.PI / 180), out X, out Y, out Z);
                ClTools.RotateYDirection(X, Y, Z, m_fAngleY * (float)(Math.PI / 180), out X, out Y, out Z);
                ClTools.RotateZDirection(X, Y, Z, m_fAngleZ * (float)(Math.PI / 180), out X, out Y, out Z);

                iter.X = X;
                iter.Y = Y;
                iter.Z = Z;

                if (!iter.MoveToNext())
                {
                    break;
                }
            }
        }
Esempio n. 21
0
 private void buttonSaveProperity_Click(object sender, EventArgs e)
 {
     try
     {
         if (listViewAlgorythm.SelectedItems.Count == 1)
         {
             int index = listViewAlgorythm.SelectedItems[0].Index;
             if (comboBoxProperityName.SelectedIndex != -1)
             {
                 string SelectedObj = comboBoxProperityName.Items[comboBoxProperityName.SelectedIndex].ToString();
                 m_lAlgorithmsList[index].SetProperitis(SelectedObj, textBoxProperityValue.Text);
             }
         }
     }
     catch (Exception ex)
     {
         Cursor.Current = Cursors.Arrow;
         MessageBox.Show(ex.Message + "\n\n Call Stack:\n\n" + ex.StackTrace, "Exception !", MessageBoxButtons.OK, MessageBoxIcon.Error);
         ClInformationSender.SendInformation("EXCEPTION\n" + ex.Message + "\n\n Call Stack:\n\n" + ex.StackTrace, ClInformationSender.eInformationType.eDebugText);
     }
 }
Esempio n. 22
0
        private void toolStripButtonReset_Click(object sender, EventArgs e)
        {
            try
            {
                ClFasadaPreprocessing.ResetFasade();
#if RENDER_1
                ClRender.getInstance().DeleteAllRenderObj();
#endif
                if (m_Model3D != null)
                {
                    m_Model3D.ResetModel();
                    m_Model3D = null;
                }
                m_sTestDirectory = "";
                this.Text        = APPLICATION_NAME + " ver. " + APPLICATION_VERSION;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + "\n\n Call Stack:\n\n" + ex.StackTrace, "Exception !", MessageBoxButtons.OK, MessageBoxIcon.Error);
                ClInformationSender.SendInformation("EXCEPTION\n" + ex.Message + "\n\n Call Stack:\n\n" + ex.StackTrace, ClInformationSender.eInformationType.eDebugText);
            }
        }
Esempio n. 23
0
        private void toolStripButtonOpen_Click(object sender, EventArgs e)
        {
            try
            {
                if (openFileDialog.ShowDialog() == DialogResult.OK)
                {
                    folderBrowserDialog.SelectedPath = "";
                    this.Text = APPLICATION_NAME + " <" + openFileDialog.FileName + ">";

                    m_Model3D = new Cl3DModel();
                    m_Model3D.LoadModel(openFileDialog.FileName);
                    #if RENDER_1
                    ClRender.getInstance().AddRenderObj(new Cl3DRenderModel(m_Model3D));
                    #endif
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + "\n\n Call Stack:\n\n" + ex.StackTrace, "Exception !", MessageBoxButtons.OK, MessageBoxIcon.Error);
                ClInformationSender.SendInformation("EXCEPTION\n" + ex.Message + "\n\n Call Stack:\n\n" + ex.StackTrace, ClInformationSender.eInformationType.eDebugText);
            }
        }
Esempio n. 24
0
        private void RenderScene()
        {
            try
            {
                while (m_bRenderScene)
                {
                    if (m_dDevice == null)
                    {
                        m_bRenderScene = false;
                        return;
                    }
                    m_dDevice.Clear(ClearFlags.Target, m_cBackgroundColor, 1.0f, 0);

                    m_dDevice.BeginScene();//Lock GPU
                    //Render primitives
                    if (m_rCamera != null)
                    {
                        m_rCamera.Render(m_dDevice, m_cRenderWindow);
                    }

                    m_dDevice.DrawUserPrimitives(PrimitiveType.LineList, m_lOrigin.Count / 2, m_lOrigin.ToArray());

                    for (int i = 0; i < m_ListRenderObjects.Count; i++)
                    {
                        m_ListRenderObjects[i].Render(m_dDevice, m_cRenderWindow);
                    }

                    m_dDevice.EndScene(); //Unlock GPU
                    m_dDevice.Present();  //Swap old with new
                }
            }
            catch (Exception ex)
            {
                m_bRenderScene = false;
                ClInformationSender.SendInformation("RENDER: " + ex.ToString(), ClInformationSender.eInformationType.eDebugText);
                return;
            }
        }
        protected override void Algorithm(ref Cl3DModel p_Model)
        {
            Cl3DModel.Cl3DModelPointIterator iter = p_Model.GetIterator();

            uint   current          = 0;
            string NeighborhoodSize = m_fNeighborhoodSize.ToString();

            if (m_bFirstNeighbor)
            {
                NeighborhoodSize = "1Neighb";
            }
            string ShapeIndexString = "ShapeIndex_" + NeighborhoodSize;

            if (iter.IsValid())
            {
                do
                {
                    double A = 0;
                    double B = 0;
                    double C = 0;
                    double D = 0;
                    double E = 0;
                    double F = 0;

                    double H               = 0;
                    double K               = 0;
                    double k1              = 0;
                    double k2              = 0;
                    double ShapeIndex      = 0;
                    double CurvednessIndex = 0;
                    List <Cl3DModel.Cl3DModelPointIterator> ListOfneighborhood;
                    double dx;
                    double dy;
                    double dxy;
                    double dxx;
                    double dyy;

                    //------------------------- Neighborhood Custom --------------------------------------------------
                    if (!iter.IsSpecificValueCalculated(ShapeIndexString) || m_bRecalculateCurvature)
                    {
                        if (!m_bFirstNeighbor)
                        {
                            ClTools.GetNeighborhoodWithGeodesicDistance(out ListOfneighborhood, iter, m_fNeighborhoodSize);
                        }
                        else
                        {
                            ListOfneighborhood = iter.GetListOfNeighbors();
                        }

                        if (m_bNeighborhoodRotation)
                        {
                            Matrix Rotation = ClTools.CalculateRotationMatrix(iter.NormalVector, new Vector(new double[] { iter.NormalVector[0], iter.NormalVector[1], 1 }));
                            List <ClTools.MainPoint3D> Neighbors = new List <ClTools.MainPoint3D>();
                            foreach (Cl3DModel.Cl3DModelPointIterator Neighb in ListOfneighborhood)
                            {
                                Matrix after = Rotation * Neighb;
                                Neighbors.Add(new ClTools.MainPoint3D((float)after[0, 0], (float)after[1, 0], (float)after[2, 0], ""));
                            }

                            if (!ClTools.CountSurfaceCoefficients(Neighbors, ref A, ref B, ref C, ref D, ref E, ref F))
                            {
                                iter.RemoveSpecificValue("Gaussian_" + NeighborhoodSize);
                                iter.RemoveSpecificValue("Mean_" + NeighborhoodSize);
                                iter.RemoveSpecificValue("K1_" + NeighborhoodSize);
                                iter.RemoveSpecificValue("K2_" + NeighborhoodSize);
                                iter.RemoveSpecificValue("ShapeIndex_" + NeighborhoodSize);
                                iter.RemoveSpecificValue("CurvednessIndex_" + NeighborhoodSize);
                                continue;
                            }
                        }
                        else
                        {
                            if (!ClTools.CountSurfaceCoefficients(ListOfneighborhood, ref A, ref B, ref C, ref D, ref E, ref F))
                            {
                                iter.RemoveSpecificValue("Gaussian_" + NeighborhoodSize);
                                iter.RemoveSpecificValue("Mean_" + NeighborhoodSize);
                                iter.RemoveSpecificValue("K1_" + NeighborhoodSize);
                                iter.RemoveSpecificValue("K2_" + NeighborhoodSize);
                                iter.RemoveSpecificValue("ShapeIndex_" + NeighborhoodSize);
                                iter.RemoveSpecificValue("CurvednessIndex_" + NeighborhoodSize);
                                continue;
                            }
                        }


                        dx  = B + 2 * D * iter.X + E * iter.Y;
                        dy  = C + E * iter.X + 2 * F * iter.Y;
                        dxy = E;
                        dxx = 2 * D;
                        dyy = 2 * F;
                        //Mean
                        H = ((((1 + Math.Pow(dy, 2)) * dxx) - (2 * dx * dy * dxy) + ((1 + Math.Pow(dx, 2)) * dyy)) / (2 * Math.Pow((1 + Math.Pow(dx, 2) + Math.Pow(dy, 2)), 3.0d / 2.0d)));
                        //Gaussian
                        K               = (((dxx * dyy) - Math.Pow(dxy, 2)) / Math.Pow((1 + Math.Pow(dx, 2) + Math.Pow(dy, 2)), 2));
                        k1              = H + Math.Sqrt(Math.Pow(H, 2) - K);
                        k2              = H - Math.Sqrt(Math.Pow(H, 2) - K);
                        ShapeIndex      = 0.5d - (1 / Math.PI) * Math.Atan((k1 + k2) / (k1 - k2));
                        CurvednessIndex = Math.Sqrt(Math.Pow(k1, 2) + Math.Pow(k2, 2)) / 2;

                        iter.AddSpecificValue("Gaussian_" + NeighborhoodSize, K);
                        iter.AddSpecificValue("Mean_" + NeighborhoodSize, H);
                        iter.AddSpecificValue("K1_" + NeighborhoodSize, k1);
                        iter.AddSpecificValue("K2_" + NeighborhoodSize, k2);
                        iter.AddSpecificValue("ShapeIndex_" + NeighborhoodSize, ShapeIndex);
                        iter.AddSpecificValue("CurvednessIndex_" + NeighborhoodSize, CurvednessIndex);
                    }

                    ClInformationSender.SendInformation((current * 100 / p_Model.ModelPointsCount).ToString(System.Globalization.CultureInfo.InvariantCulture), ClInformationSender.eInformationType.eProgress);
                    current++;
                } while (iter.MoveToNext());
            }
        }
        private void MarkHighCurvEdges(ref Cl3DModel Model)
        {
            Cl3DModel.Cl3DModelPointIterator NoseTip  = Model.GetSpecificPoint(Cl3DModel.eSpecificPoints.NoseTip);
            Cl3DModel.Cl3DModelPointIterator LeftEye  = Model.GetSpecificPoint(Cl3DModel.eSpecificPoints.LeftEyeRightCorner);
            Cl3DModel.Cl3DModelPointIterator RightEye = Model.GetSpecificPoint(Cl3DModel.eSpecificPoints.RightEyeLeftCorner);

            float diistance = (float)Math.Sqrt(Math.Pow(NoseTip - LeftEye, 2) + Math.Pow(NoseTip - RightEye, 2) + Math.Pow(LeftEye - RightEye, 2)) * 1.15f;

            List <Cl3DModel.Cl3DModelPointIterator> pointsIn = new List <Cl3DModel.Cl3DModelPointIterator>();

            Cl3DModel.Cl3DModelPointIterator iter = Model.GetIterator();
            do
            {
                float dist = (float)Math.Sqrt(Math.Pow((float)(iter - NoseTip), 2) + Math.Pow((float)(iter - LeftEye), 2) + Math.Pow((float)(iter - RightEye), 2));
                if (dist < diistance)
                {
                    pointsIn.Add(iter.CopyIterator());
                }
            } while (iter.MoveToNext());

            double MaxK1_10 = double.MinValue;
            double MinK1_10 = double.MaxValue;

            double MaxK1_15 = double.MinValue;
            double MinK1_15 = double.MaxValue;

            double MaxK1_20 = double.MinValue;
            double MinK1_20 = double.MaxValue;

            double MaxK1_25 = double.MinValue;
            double MinK1_25 = double.MaxValue;

            double MaxK1_55 = double.MinValue;
            double MinK1_40 = double.MaxValue;

            foreach (Cl3DModel.Cl3DModelPointIterator PointIn in pointsIn)
            {
                double valK1_10;
                if (!PointIn.GetSpecificValue(Cl3DModel.Cl3DModelPointIterator.eSpecificValues.K1_10, out valK1_10))
                {
                    ClInformationSender.SendInformation("K1 10 unavailable for the point " + PointIn.PointID.ToString(), ClInformationSender.eInformationType.eDebugText);
                    continue;
                }

                double valK1_15;
                if (!PointIn.GetSpecificValue(Cl3DModel.Cl3DModelPointIterator.eSpecificValues.K1_15, out valK1_15))
                {
                    ClInformationSender.SendInformation("K1 15 unavailable for the point " + PointIn.PointID.ToString(), ClInformationSender.eInformationType.eDebugText);
                    continue;
                }

                double valK1_20;
                if (!PointIn.GetSpecificValue(Cl3DModel.Cl3DModelPointIterator.eSpecificValues.K1_20, out valK1_20))
                {
                    ClInformationSender.SendInformation("K1 20 unavailable for the point " + PointIn.PointID.ToString(), ClInformationSender.eInformationType.eDebugText);
                    continue;
                }

                double valK1_25;
                if (!PointIn.GetSpecificValue(Cl3DModel.Cl3DModelPointIterator.eSpecificValues.K1_25, out valK1_25))
                {
                    ClInformationSender.SendInformation("K1 25 unavailable for the point " + PointIn.PointID.ToString(), ClInformationSender.eInformationType.eDebugText);
                    continue;
                }

                double valK1_40;
                if (!PointIn.GetSpecificValue(Cl3DModel.Cl3DModelPointIterator.eSpecificValues.K1_40, out valK1_40))
                {
                    ClInformationSender.SendInformation("K1 40 unavailable for the point " + PointIn.PointID.ToString(), ClInformationSender.eInformationType.eDebugText);
                    continue;
                }

                if (MinK1_10 > valK1_10)
                {
                    MinK1_10 = valK1_10;
                }
                if (MaxK1_10 < valK1_10)
                {
                    MaxK1_10 = valK1_10;
                }

                if (MinK1_15 > valK1_15)
                {
                    MinK1_15 = valK1_15;
                }
                if (MaxK1_15 < valK1_15)
                {
                    MaxK1_15 = valK1_15;
                }

                if (MinK1_20 > valK1_20)
                {
                    MinK1_20 = valK1_20;
                }
                if (MaxK1_20 < valK1_20)
                {
                    MaxK1_20 = valK1_20;
                }

                if (MinK1_25 > valK1_25)
                {
                    MinK1_25 = valK1_25;
                }
                if (MaxK1_25 < valK1_25)
                {
                    MaxK1_25 = valK1_25;
                }

                if (MinK1_40 > valK1_40)
                {
                    MinK1_40 = valK1_40;
                }
                if (MaxK1_55 < valK1_40)
                {
                    MaxK1_55 = valK1_40;
                }
            }

            iter = Model.GetIterator();
            do
            {
                double valK1_10;
                if (!iter.GetSpecificValue(Cl3DModel.Cl3DModelPointIterator.eSpecificValues.K1_10, out valK1_10))
                {
                    continue;
                }

                double valK1_15;
                if (!iter.GetSpecificValue(Cl3DModel.Cl3DModelPointIterator.eSpecificValues.K1_15, out valK1_15))
                {
                    continue;
                }

                double valK1_20;
                if (!iter.GetSpecificValue(Cl3DModel.Cl3DModelPointIterator.eSpecificValues.K1_20, out valK1_20))
                {
                    continue;
                }

                double valK1_25;
                if (!iter.GetSpecificValue(Cl3DModel.Cl3DModelPointIterator.eSpecificValues.K1_25, out valK1_25))
                {
                    continue;
                }

                double valK1_40;
                if (!iter.GetSpecificValue(Cl3DModel.Cl3DModelPointIterator.eSpecificValues.K1_40, out valK1_40))
                {
                    continue;
                }

                if (valK1_10 < MinK1_10 || valK1_10 > MaxK1_10 ||
                    valK1_15 < MinK1_15 || valK1_15 > MaxK1_15 ||
                    valK1_20 < MinK1_20 || valK1_20 > MaxK1_20 ||
                    valK1_25 < MinK1_25 || valK1_25 > MaxK1_25 ||
                    valK1_40 < MinK1_40 || valK1_40 > MaxK1_55
                    )
                {
                    // iter.Color = Color.LightBlue;
                    iter.AddSpecificValue("ToRemove_HighCurvature", 1.0f);
                }
            } while (iter.MoveToNext());
        }
        protected override void Algorithm(ref Cl3DModel p_Model)
        {
            MarkHighCurvEdges(ref p_Model);

            p_Model.ResetVisitedPoints();
            //-------------------------------- Cropping
            Cl3DModel.Cl3DModelPointIterator NoseTip  = p_Model.GetSpecificPoint(Cl3DModel.eSpecificPoints.NoseTip);
            Cl3DModel.Cl3DModelPointIterator LeftEye  = p_Model.GetSpecificPoint(Cl3DModel.eSpecificPoints.LeftEyeRightCorner);
            Cl3DModel.Cl3DModelPointIterator RightEye = p_Model.GetSpecificPoint(Cl3DModel.eSpecificPoints.RightEyeLeftCorner);

            float distanceBetweenEyes = LeftEye - RightEye;
            float ossfest             = distanceBetweenEyes * 0.4f; //20% of distance between eyes will be taken as a stripe down to search for the mouth hole

            Cl3DModel.Cl3DModelPointIterator iter = p_Model.GetIterator();
            Dictionary <uint, Cl3DModel.Cl3DModelPointIterator> pointsToRemove = new Dictionary <uint, Cl3DModel.Cl3DModelPointIterator>();

            do
            {
                if (iter.X > LeftEye.X + ossfest && iter.X < RightEye.X - ossfest && iter.Y < NoseTip.Y - 20 && iter.Y > NoseTip.Y - 43)
                {
                    // iter.Color = Color.LightBlue;
                    if (iter.IsSpecificValueCalculated("ToRemove_HighCurvature"))
                    {
                        pointsToRemove.Add(iter.PointID, iter.CopyIterator());
                    }
                }
            } while (iter.MoveToNext());

            List <List <Cl3DModel.Cl3DModelPointIterator> > ListOfRegions = new List <List <Cl3DModel.Cl3DModelPointIterator> >();

            while (pointsToRemove.Count != 0)
            {
                Cl3DModel.Cl3DModelPointIterator test = new List <Cl3DModel.Cl3DModelPointIterator>(pointsToRemove.Values)[0];
                pointsToRemove.Remove(test.PointID);

                bool toRemove = false;
                List <Cl3DModel.Cl3DModelPointIterator> CurrentList = new List <Cl3DModel.Cl3DModelPointIterator>();
                ListOfRegions.Add(CurrentList);

                List <Cl3DModel.Cl3DModelPointIterator> ToCheck = new List <Cl3DModel.Cl3DModelPointIterator>();
                ToCheck.Add(test);
                test.AlreadyVisited = true;
                do
                {
                    List <Cl3DModel.Cl3DModelPointIterator> NewToCheck = new List <Cl3DModel.Cl3DModelPointIterator>();
                    foreach (Cl3DModel.Cl3DModelPointIterator pt in ToCheck)
                    {
                        CurrentList.Add(pt.CopyIterator());

                        foreach (Cl3DModel.Cl3DModelPointIterator ptNb in pt.GetListOfNeighbors())
                        {
                            if (ptNb.IsSpecificValueCalculated("ToRemove_HighCurvature") && ptNb.AlreadyVisited == false)
                            {
                                ptNb.AlreadyVisited = true;
                                NewToCheck.Add(ptNb.CopyIterator());
                                pointsToRemove.Remove(ptNb.PointID);
                                List <Cl3DModel.Cl3DModelPointIterator> Neighbors = ptNb.GetListOfNeighbors();

                                //   if (Neighbors.Count < 8) // that means the points from marked region went to the end of the model very rare happens that the open mouth region is the externatl region
                                //       toRemove = true;
                            }
                        }
                    }
                    ToCheck    = NewToCheck;
                    NewToCheck = new List <Cl3DModel.Cl3DModelPointIterator>();
                } while (ToCheck.Count != 0);
                if (toRemove)
                {
                    ListOfRegions.Remove(CurrentList);
                }
            }

            List <Cl3DModel.Cl3DModelPointIterator> BiggestRegion = null;
            int SizeOfTheBiggest = int.MinValue;

            for (int i = 0; i < ListOfRegions.Count; i++)
            {
                if (ListOfRegions[i].Count > SizeOfTheBiggest)
                {
                    SizeOfTheBiggest = ListOfRegions[i].Count;
                    BiggestRegion    = ListOfRegions[i];
                }
            }

            //------------------- Creating image of localized mouth part

            /*   int NoseX = NoseTip.RangeImageX;
             * int NoseY = NoseTip.RangeImageY;
             * //BiggestRegion
             * int[,] FMap = null;
             * if (!FaceMaps.TryGetValue(p_Model.m_sExpression, out FMap))
             * {
             *     FMap = new int[200, 200];
             *     FaceMaps.Add(p_Model.m_sExpression, FMap);
             * }
             * Cl3DModel.Cl3DModelPointIterator its = p_Model.GetIterator();
             * do
             * {
             *     int currX = its.RangeImageX;
             *     int currY = its.RangeImageY;
             *
             *
             *     int x = currX - NoseX + 100;
             *     int y = currY - NoseY + 100;
             *
             *     FMap[x, y]++;
             * } while (its.MoveToNext());
             *
             * int MaxF = int.MinValue;
             * for (int i = 0; i < 200; i++)
             *     for(int j=0; j< 200; j++)
             *         if (FMap[i, j] > MaxF)
             *             MaxF = FMap[i, j];
             *
             *
             * //-
             * int[,] FRem = null;
             * if (!RemovedMaps.TryGetValue(p_Model.m_sExpression, out FRem))
             * {
             *     FRem = new int[200, 200];
             *     RemovedMaps.Add(p_Model.m_sExpression, FRem);
             * }
             *
             * if (BiggestRegion != null)
             * {
             *     foreach (Cl3DModel.Cl3DModelPointIterator pp in BiggestRegion)
             *     {
             *         int currX = pp.RangeImageX;
             *         int currY = pp.RangeImageY;
             *
             *
             *         int x = currX - NoseX + 100;
             *         int y = currY - NoseY + 100;
             *
             *         FRem[x, y]++;
             *     }
             * }
             *
             * FRem[NoseTip.RangeImageX - NoseX + 100, NoseTip.RangeImageY - NoseY + 100]++;
             * //  FRem[LeftEye.RangeImageX - NoseX + 100, LeftEye.RangeImageY - NoseY + 100]++;
             * //  FRem[RightEye.RangeImageX - NoseX + 100, RightEye.RangeImageY - NoseY + 100]++;
             *
             *
             * int MaxR = int.MinValue;
             * for (int i = 0; i < 200; i++)
             *     for (int j = 0; j < 200; j++)
             *         if (FRem[i, j] > MaxR)
             *             MaxR = FRem[i, j];
             *
             *
             *
             *
             *
             *
             *
             *
             *
             * Bitmap map = new Bitmap(200, 200);
             * for (int i = 0; i < 200; i++)
             * {
             *     for (int j = 0; j < 200; j++)
             *     {
             *         map.SetPixel(i, j, ClTools.GetColorGray(((float)FMap[i, j]) / MaxF, 1.0f));
             *         if(FRem[i, j] != 0)
             *             map.SetPixel(i, j, ClTools.GetColorGray( 1 - ((float)FRem[i, j]) / MaxR, 1.0f));
             *     }
             * }
             * map.Save("d:\\" + p_Model.m_sExpression + ".bmp");
             * return;
             */
            //------------------------------------------------------------

            /*  TextWriter tw = new StreamWriter("d:\\MouthSizeBosphorus2.txt", false);
             *
             *
             * int ssize = 0;
             * if (BiggestRegion != null)
             *    ssize = BiggestRegion.Count;
             *
             * int[] OldSize;
             * if(!mouthSize.TryGetValue(p_Model.m_sExpression, out OldSize))
             * {
             *    OldSize = new int[2];
             *    mouthSize.Add(p_Model.m_sExpression, OldSize);
             * }
             * OldSize[0] += ssize;
             * OldSize[1]++;
             *
             * foreach(KeyValuePair<string, int[]> val in mouthSize)
             *    tw.WriteLine(val.Key+" "+ val.Value[0].ToString()+ " " + val.Value[1].ToString());
             *
             * tw.Close();
             *
             * return;
             */
            //----------------------------------------------------------------

            //---------------------- NO mouth REGION LOCALIZED
            if (BiggestRegion == null)
            {
                ClInformationSender.SendInformation("No mouth localized, normal Geodesic distance calculation", ClInformationSender.eInformationType.eDebugText);
                if (m_bRemoveRegions) // still there can be vertexes with high curvature (edges between hair and the face)
                {
                    Cl3DModel.Cl3DModelPointIterator remover = p_Model.GetIterator();
                    while (remover.IsValid())
                    {
                        if (remover.IsSpecificValueCalculated("ToRemove_HighCurvature"))
                        {
                            remover = p_Model.RemovePointFromModel(remover);
                        }
                        else
                        {
                            remover.MoveToNext();
                        }
                    }
                }

                ClTools.CalculateGeodesicDistanceFromSourcePointToAllPoints(NoseTip, Cl3DModel.Cl3DModelPointIterator.eSpecificValues.GeodesicDistanceToNoseTip.ToString());

                if (!m_bCrop)
                {
                    return;
                }

                iter = p_Model.GetIterator();
                while (iter.IsValid())
                {
                    if (!iter.IsSpecificValueCalculated(Cl3DModel.Cl3DModelPointIterator.eSpecificValues.GeodesicDistanceToNoseTip))
                    {
                        iter = p_Model.RemovePointFromModel(iter);
                    }
                    else
                    {
                        double distance = iter.GetSpecificValue(Cl3DModel.Cl3DModelPointIterator.eSpecificValues.GeodesicDistanceToNoseTip);
                        if (distance > m_fDistence)
                        {
                            iter = p_Model.RemovePointFromModel(iter);
                        }
                        else
                        {
                            iter.MoveToNext();
                        }
                    }
                }
                return;
            }

            //------------------------- Mouth REGION LOCALiZED
            p_Model.ResetVisitedPoints();
            List <Cl3DModel.Cl3DModelPointIterator> BorderOfTheBigestRegion = new List <Cl3DModel.Cl3DModelPointIterator>();

            foreach (Cl3DModel.Cl3DModelPointIterator pts in BiggestRegion)
            {
                if (m_bMarkRegion)
                {
                    pts.Color = Color.Red;
                }

                List <Cl3DModel.Cl3DModelPointIterator> neighb = pts.GetListOfNeighbors();
                foreach (Cl3DModel.Cl3DModelPointIterator ppt in neighb)
                {
                    if (!ppt.AlreadyVisited && !ppt.IsSpecificValueCalculated("ToRemove_HighCurvature"))
                    {
                        BorderOfTheBigestRegion.Add(ppt);
                        ppt.AlreadyVisited = true;
                    }
                }
            }

            if (m_bRemoveRegions) // After we have border of the mouth region we can remove them
            {
                Cl3DModel.Cl3DModelPointIterator remover = p_Model.GetIterator();
                while (remover.IsValid())
                {
                    if (remover.IsSpecificValueCalculated("ToRemove_HighCurvature"))
                    {
                        remover = p_Model.RemovePointFromModel(remover);
                    }
                    else
                    {
                        remover.MoveToNext();
                    }
                }
            }

            Cl3DModel.Cl3DModelPointIterator MaxLeft  = BorderOfTheBigestRegion[0];
            Cl3DModel.Cl3DModelPointIterator MaxRight = BorderOfTheBigestRegion[0];
            foreach (Cl3DModel.Cl3DModelPointIterator pt in BorderOfTheBigestRegion)
            {
                if (pt.X < MaxLeft.X)
                {
                    MaxLeft = pt;
                }
                if (pt.X > MaxRight.X)
                {
                    MaxRight = pt;
                }
            }

            int size = (int)Math.Abs(MaxLeft.X - MaxRight.X) + 1;

            List <Cl3DModel.Cl3DModelPointIterator>[] histogram = new List <Cl3DModel.Cl3DModelPointIterator> [size];

            foreach (Cl3DModel.Cl3DModelPointIterator pt in BorderOfTheBigestRegion)
            {
                int pos = (int)(pt.X - MaxLeft.X);
                if (histogram[pos] == null)
                {
                    histogram[pos] = new List <Cl3DModel.Cl3DModelPointIterator>();
                }

                histogram[pos].Add(pt);
            }

            Dictionary <uint, uint> movingPoints = new Dictionary <uint, uint>();

            for (int i = 0; i < size; i++)
            {
                if (histogram[i] != null && histogram[i].Count != 0)
                {
                    //Color cl = ClTools.GetColorRGB(((float)i) / size, 1.0f);
                    Cl3DModel.Cl3DModelPointIterator UpperPoint = histogram[i][0];
                    Cl3DModel.Cl3DModelPointIterator LowerPoint = histogram[i][0];
                    foreach (Cl3DModel.Cl3DModelPointIterator pts in histogram[i])
                    {
                        //  pts.Color = cl;
                        if (UpperPoint.Y < pts.Y)
                        {
                            UpperPoint = pts;
                        }
                        if (LowerPoint.Y > pts.Y)
                        {
                            LowerPoint = pts;
                        }
                    }
                    //UpperPoint from this one
                    if (UpperPoint.PointID != LowerPoint.PointID)
                    {
                        float distance = Math.Min(LowerPoint - MaxLeft, LowerPoint - MaxRight);
                        List <Cl3DModel.Cl3DModelPointIterator> neighborhood = null;
                        ClTools.GetNeighborhoodWithGeodesicDistance(out neighborhood, LowerPoint, distance);
                        Cl3DModel.Cl3DModelPointIterator ClosestPoint = LowerPoint;
                        float MinDistance = LowerPoint - UpperPoint;
                        foreach (Cl3DModel.Cl3DModelPointIterator ptNeighb in neighborhood)
                        {
                            // ptNeighb.Color = Color.Pink;
                            float newDistance = ptNeighb - UpperPoint;
                            if (newDistance < MinDistance)
                            {
                                MinDistance  = newDistance;
                                ClosestPoint = ptNeighb;
                            }
                        }
                        Color cl = ClTools.GetColorRGB(((float)i) / size, 1.0f);
                        //    ClosestPoint.Color = cl;
                        //    UpperPoint.Color = cl;
                        movingPoints.Add(UpperPoint.PointID, ClosestPoint.PointID);
                    }
                }
            }

            //-------------------------------- Calculation of the geodesic using movement points
            p_Model.ResetVisitedPoints();
            ClTools.CalculateGeodesicDistanceFromSourcePointToAllPointsWithMovement(NoseTip, Cl3DModel.Cl3DModelPointIterator.eSpecificValues.GeodesicDistanceToNoseTip.ToString(), movingPoints);

            if (!m_bCrop)
            {
                return;
            }

            iter = p_Model.GetIterator();
            while (iter.IsValid())
            {
                if (!iter.IsSpecificValueCalculated(Cl3DModel.Cl3DModelPointIterator.eSpecificValues.GeodesicDistanceToNoseTip))
                {
                    iter = p_Model.RemovePointFromModel(iter);
                }
                else
                {
                    double distance = iter.GetSpecificValue(Cl3DModel.Cl3DModelPointIterator.eSpecificValues.GeodesicDistanceToNoseTip);
                    if (distance > m_fDistence)
                    {
                        iter = p_Model.RemovePointFromModel(iter);
                    }
                    else
                    {
                        iter.MoveToNext();
                    }
                }
            }
        }
Esempio n. 28
0
        protected override void Algorithm(ref Cl3DModel p_Model)
        {
            Cl3DModel.Cl3DModelPointIterator iter = p_Model.GetIterator();

            if (!iter.IsValid())
            {
                return;
            }

            List <Cl3DModel.Cl3DModelPointIterator> ListOfNosePoints = new List <Cl3DModel.Cl3DModelPointIterator>();
            List <Cl3DModel.Cl3DModelPointIterator> ListOfEyesPoints = new List <Cl3DModel.Cl3DModelPointIterator>();
            string gausString = "Gaussian_" + m_iNeighborhoodSize.ToString();
            string meanString = "Mean_" + m_iNeighborhoodSize.ToString();

            do
            {
                double H = 0;
                double K = 0;

                if (!iter.GetSpecificValue(gausString, out K))
                {
                    continue;
                }
                if (!iter.GetSpecificValue(meanString, out H))
                {
                    continue;
                }

                if (H < 0 && K > m_NoseThresholdK) //  Nose
                {
                    ListOfNosePoints.Add(iter.CopyIterator());
                }
                else if (H > 0 && K > m_EyesThresholdK) //  Eyes
                {
                    ListOfEyesPoints.Add(iter.CopyIterator());
                }
            }while (iter.MoveToNext());

            List <List <Cl3DModel.Cl3DModelPointIterator> > NoseRegions = null;
            List <List <Cl3DModel.Cl3DModelPointIterator> > EyesRegions = null;

            // NOSE
            DivideToTheRegions(ListOfNosePoints, out NoseRegions);

            // EYES
            DivideToTheRegions(ListOfEyesPoints, out EyesRegions);

            // COLOR IT

            /*for (int i = 0; i < NoseRegions.Count; i++)
             * {
             *  foreach (Cl3DModel.Cl3DModelPointIterator point in NoseRegions[i])
             *      point.Color = ClTools.GetColorRGB((float)i / (NoseRegions.Count + EyesRegions.Count), 1);
             * }
             * for (int i = 0; i < EyesRegions.Count; i++)
             * {
             *  foreach (Cl3DModel.Cl3DModelPointIterator point in EyesRegions[i])
             *      point.Color = ClTools.GetColorRGB((float)(i + NoseRegions.Count) / (EyesRegions.Count + NoseRegions.Count), 1);
             * }
             */

            // -----------------  NOSE
            // remove smallest regions leave only 3 biggest one
            List <Cl3DModel.Cl3DModelPointIterator> NoseTipsPoints = new List <Cl3DModel.Cl3DModelPointIterator>();

            if (NoseRegions.Count > m_iMaxCountOfNoseRegions)
            {
                NoseRegions.Sort(new ClCompareCount());
                for (int i = NoseRegions.Count - 1; i >= m_iMaxCountOfNoseRegions; i--)
                {
                    NoseRegions.RemoveAt(i);
                }
            }
            //----------- NOSE searching for one point in each region
            for (int i = 0; i < NoseRegions.Count; i++)
            {
                double MaxKVal = 0;
                Cl3DModel.Cl3DModelPointIterator MaxPoint = null;
                foreach (Cl3DModel.Cl3DModelPointIterator point in NoseRegions[i])
                {
                    double K;
                    if (!point.GetSpecificValue(gausString, out K))
                    {
                        continue;
                    }

                    if (MaxPoint == null)
                    {
                        MaxPoint = point;
                        MaxKVal  = K;
                        continue;
                    }

                    if (MaxKVal < K)
                    {
                        MaxKVal  = K;
                        MaxPoint = point;
                    }
                }
                NoseTipsPoints.Add(MaxPoint);
            }

            // ---------------  EYES
            // remove smallest regions leave only 5 biggest one
            List <Cl3DModel.Cl3DModelPointIterator> EyesPoints = new List <Cl3DModel.Cl3DModelPointIterator>();

            if (EyesRegions.Count > m_iMaxCountOfEyeRegions)
            {
                EyesRegions.Sort(new ClCompareCount());
                for (int i = EyesRegions.Count - 1; i >= m_iMaxCountOfEyeRegions; i--)
                {
                    EyesRegions.RemoveAt(i);
                }
            }
            //--------------------------- EYES searching for one point in each region
            for (int i = 0; i < EyesRegions.Count; i++)
            {
                double MaxKval = 0;
                Cl3DModel.Cl3DModelPointIterator MinPoint = null;

                foreach (Cl3DModel.Cl3DModelPointIterator point in EyesRegions[i])
                {
                    double val;
                    if (!point.GetSpecificValue(gausString, out val))
                    {
                        continue;
                    }

                    if (MinPoint == null)
                    {
                        MinPoint = point;
                        MaxKval  = val;
                        continue;
                    }

                    if (MaxKval < val)
                    {
                        MaxKval  = val;
                        MinPoint = point;
                    }
                }
                EyesPoints.Add(MinPoint);
            }
            //------------- Looking for three face points ------------------------------
            Iridium.Numerics.LinearAlgebra.Matrix Model    = new Iridium.Numerics.LinearAlgebra.Matrix(3, 3);
            Iridium.Numerics.LinearAlgebra.Matrix ModelGen = new Iridium.Numerics.LinearAlgebra.Matrix(3, 3);

            // Generic model
            Vector GenericNoseTip  = new Vector(new double[] { 0, 0, 0 });
            Vector GenericLeftEye  = new Vector(new double[] { -21f, 40.5f, -41.5f });
            Vector GenericRightEye = new Vector(new double[] { 21f, 40.5f, -41.5f });

            Vector GenLeftCornerOfLeftEye   = new Vector(new double[] { -44f, 40f, -44f });
            Vector GenRightCornerOfRightEye = new Vector(new double[] { 44f, 40f, -44f });

            Vector GenLeftCornerOfNose  = new Vector(new double[] { -20f, -2f, -31f });
            Vector GenRightCornerOfNose = new Vector(new double[] { 20f, -2f, -31f });

            Vector GenLeftCornerOfLips  = new Vector(new double[] { -28f, -32f, -34f });
            Vector GenRightCornerOfLips = new Vector(new double[] { 28f, -32f, -34f });


            Vector MeanGenericModel = new Vector(new double[] { (GenericNoseTip[0] + GenericLeftEye[0] + GenericRightEye[0]) / 3,
                                                                (GenericNoseTip[1] + GenericLeftEye[1] + GenericRightEye[1]) / 3,
                                                                (GenericNoseTip[2] + GenericLeftEye[2] + GenericRightEye[2]) / 3 });

            // Centered generic model (generic model - mean)
            ModelGen[0, 0] = (GenericNoseTip[0] - MeanGenericModel[0]);
            ModelGen[1, 0] = (GenericNoseTip[1] - MeanGenericModel[1]);
            ModelGen[2, 0] = (GenericNoseTip[2] - MeanGenericModel[2]);

            ModelGen[0, 1] = (GenericLeftEye[0] - MeanGenericModel[0]);
            ModelGen[1, 1] = (GenericLeftEye[1] - MeanGenericModel[1]);
            ModelGen[2, 1] = (GenericLeftEye[2] - MeanGenericModel[2]);

            ModelGen[0, 2] = (GenericRightEye[0] - MeanGenericModel[0]);
            ModelGen[1, 2] = (GenericRightEye[1] - MeanGenericModel[1]);
            ModelGen[2, 2] = (GenericRightEye[2] - MeanGenericModel[2]);
            ModelGen.Transpose();

            List <KeyValuePair <float, List <Cl3DModel.Cl3DModelPointIterator> > > deltaOfDistanceBetweenModelAndPoints = new List <KeyValuePair <float, List <Cl3DModel.Cl3DModelPointIterator> > >();

            for (int iEye = 0; iEye < EyesPoints.Count - 1; iEye++)
            {
                for (int jEye = iEye + 1; jEye < EyesPoints.Count; jEye++)
                {
                    for (int iNose = 0; iNose < NoseTipsPoints.Count; iNose++)
                    {
                        Cl3DModel.Cl3DModelPointIterator eyeLeft  = EyesPoints[iEye];
                        Cl3DModel.Cl3DModelPointIterator eyeRight = EyesPoints[jEye];
                        Cl3DModel.Cl3DModelPointIterator noseTip  = NoseTipsPoints[iNose];

                        if (eyeLeft.Y < noseTip.Y || eyeRight.Y < noseTip.Y)
                        {
                            continue;
                        }

                        for (int c = 0; c < 2; c++)
                        {
                            if (c == 1)
                            {
                                eyeLeft  = EyesPoints[jEye]; // zmiana oczu nie wiemy ktore punkty to oczy prawdziwe sa
                                eyeRight = EyesPoints[iEye];
                            }

                            float MeanValX = (noseTip.X + eyeLeft.X + eyeRight.X) / 3.0f;
                            float MeanValY = (noseTip.Y + eyeLeft.Y + eyeRight.Y) / 3.0f;
                            float MeanValZ = (noseTip.Z + eyeLeft.Z + eyeRight.Z) / 3.0f;

                            Model[0, 0] = (noseTip.X - MeanValX);
                            Model[1, 0] = (noseTip.Y - MeanValY);
                            Model[2, 0] = (noseTip.Z - MeanValZ);

                            Model[0, 1] = (eyeLeft.X - MeanValX);
                            Model[1, 1] = (eyeLeft.Y - MeanValY);
                            Model[2, 1] = (eyeLeft.Z - MeanValZ);

                            Model[0, 2] = (eyeRight.X - MeanValX);
                            Model[1, 2] = (eyeRight.Y - MeanValY);
                            Model[2, 2] = (eyeRight.Z - MeanValZ);


                            //----------------- Finding best rotation and translation SVD algorithm

                            Iridium.Numerics.LinearAlgebra.Matrix Covariance = Model * ModelGen;

                            Iridium.Numerics.LinearAlgebra.SingularValueDecomposition SVD = new Iridium.Numerics.LinearAlgebra.SingularValueDecomposition(Covariance);
                            Iridium.Numerics.LinearAlgebra.Matrix U = SVD.LeftSingularVectors;
                            Iridium.Numerics.LinearAlgebra.Matrix V = SVD.RightSingularVectors;

                            Iridium.Numerics.LinearAlgebra.Matrix s = new Iridium.Numerics.LinearAlgebra.Matrix(3, 1.0);

                            if (Covariance.Rank() < 2)
                            {
                                throw new Exception("Cannot allign generic model (cov rank is less than 2)");
                            }

                            if (Covariance.Rank() == 2) // m-1 where m is dimension space (3D)
                            {
                                double detU = Math.Round(U.Determinant());
                                double detV = Math.Round(V.Determinant());
                                double detC = Covariance.Determinant();
                                if ((int)detU * (int)detV == 1)
                                {
                                    s[2, 2] = 1;
                                }
                                else if ((int)detU * (int)detV == -1)
                                {
                                    s[2, 2] = -1;
                                }
                                else
                                {
                                    throw new Exception("Determinant of U and V are not in conditions");
                                }
                            }
                            else
                            {
                                if (Covariance.Determinant() < 0)
                                {
                                    s[2, 2] = -1;
                                }
                            }

                            V.Transpose();
                            Iridium.Numerics.LinearAlgebra.Matrix Roatation = U * s * V;

                            Iridium.Numerics.LinearAlgebra.Matrix MeanValOfGenModelMatrix = new Iridium.Numerics.LinearAlgebra.Matrix(3, 1);
                            MeanValOfGenModelMatrix[0, 0] = MeanGenericModel[0];
                            MeanValOfGenModelMatrix[1, 0] = MeanGenericModel[1];
                            MeanValOfGenModelMatrix[2, 0] = MeanGenericModel[2];

                            Iridium.Numerics.LinearAlgebra.Matrix MeanValOfModelMatrix = new Iridium.Numerics.LinearAlgebra.Matrix(3, 1);
                            MeanValOfModelMatrix[0, 0] = MeanValX;
                            MeanValOfModelMatrix[1, 0] = MeanValY;
                            MeanValOfModelMatrix[2, 0] = MeanValZ;

                            Iridium.Numerics.LinearAlgebra.Matrix Translation = MeanValOfModelMatrix - Roatation * MeanValOfGenModelMatrix;

                            //--------------------------- End now we have translation and rotation

                            float GenericModelDistance = 0;;

                            Iridium.Numerics.LinearAlgebra.Matrix q = new Iridium.Numerics.LinearAlgebra.Matrix(3, 1);
                            q[0, 0] = GenericNoseTip[0];
                            q[1, 0] = GenericNoseTip[1];
                            q[2, 0] = GenericNoseTip[2];
                            Iridium.Numerics.LinearAlgebra.Matrix NewQ = Roatation * q + Translation;
                            GenericModelDistance += (float)Math.Sqrt(Math.Pow(noseTip.X - NewQ[0, 0], 2) + Math.Pow(noseTip.Y - NewQ[1, 0], 2) + Math.Pow(noseTip.Z - NewQ[2, 0], 2));
                            //---------
                            //    Cl3DModel.Cl3DModelPointIterator it1 = p_Model.AddPointToModel((float)NewQ[0, 0], (float)NewQ[1, 0], (float)NewQ[2, 0]);
                            //it1.AddNeighbor(noseTip);
                            //    it1.Color = Color.Green;
                            //---------
                            q[0, 0] = GenericLeftEye[0];
                            q[1, 0] = GenericLeftEye[1];
                            q[2, 0] = GenericLeftEye[2];
                            NewQ    = Roatation * q + Translation;
                            GenericModelDistance += (float)Math.Sqrt(Math.Pow(eyeLeft.X - NewQ[0, 0], 2) + Math.Pow(eyeLeft.Y - NewQ[1, 0], 2) + Math.Pow(eyeLeft.Z - NewQ[2, 0], 2));
                            //---------
                            //    Cl3DModel.Cl3DModelPointIterator it2 = p_Model.AddPointToModel((float)NewQ[0, 0], (float)NewQ[1, 0], (float)NewQ[2, 0]);
                            //it2.AddNeighbor(eyeLeft);
                            //    it2.Color = Color.White;
                            //---------

                            q[0, 0] = GenericRightEye[0];
                            q[1, 0] = GenericRightEye[1];
                            q[2, 0] = GenericRightEye[2];
                            NewQ    = Roatation * q + Translation;
                            GenericModelDistance += (float)Math.Sqrt(Math.Pow(eyeRight.X - NewQ[0, 0], 2) + Math.Pow(eyeRight.Y - NewQ[1, 0], 2) + Math.Pow(eyeRight.Z - NewQ[2, 0], 2));
                            //---------
                            //    Cl3DModel.Cl3DModelPointIterator it3 = p_Model.AddPointToModel((float)NewQ[0, 0], (float)NewQ[1, 0], (float)NewQ[2, 0]);
                            //it3.AddNeighbor(eyeRight);
                            //    it3.Color = Color.Orange;

                            //    it1.AddNeighbor(it2);
                            //    it1.AddNeighbor(it3);
                            //    it2.AddNeighbor(it3);
                            //---------

                            // ---------- Rest of generic model to find closest points and count distance;
                            q[0, 0] = GenLeftCornerOfLeftEye[0];
                            q[1, 0] = GenLeftCornerOfLeftEye[1];
                            q[2, 0] = GenLeftCornerOfLeftEye[2];
                            NewQ    = Roatation * q + Translation;
                            Cl3DModel.Cl3DModelPointIterator closestPoint = null;
                            float MinDistance;
                            ClTools.FindClosestPointInModel(p_Model, (float)NewQ[0, 0], (float)NewQ[1, 0], (float)NewQ[2, 0], out closestPoint, out MinDistance);
                            GenericModelDistance += MinDistance;

                            q[0, 0] = GenRightCornerOfRightEye[0];
                            q[1, 0] = GenRightCornerOfRightEye[1];
                            q[2, 0] = GenRightCornerOfRightEye[2];
                            NewQ    = Roatation * q + Translation;
                            ClTools.FindClosestPointInModel(p_Model, (float)NewQ[0, 0], (float)NewQ[1, 0], (float)NewQ[2, 0], out closestPoint, out MinDistance);
                            GenericModelDistance += MinDistance;

                            q[0, 0] = GenLeftCornerOfNose[0];
                            q[1, 0] = GenLeftCornerOfNose[1];
                            q[2, 0] = GenLeftCornerOfNose[2];
                            NewQ    = Roatation * q + Translation;
                            ClTools.FindClosestPointInModel(p_Model, (float)NewQ[0, 0], (float)NewQ[1, 0], (float)NewQ[2, 0], out closestPoint, out MinDistance);
                            GenericModelDistance += MinDistance;

                            q[0, 0] = GenRightCornerOfNose[0];
                            q[1, 0] = GenRightCornerOfNose[1];
                            q[2, 0] = GenRightCornerOfNose[2];
                            NewQ    = Roatation * q + Translation;
                            ClTools.FindClosestPointInModel(p_Model, (float)NewQ[0, 0], (float)NewQ[1, 0], (float)NewQ[2, 0], out closestPoint, out MinDistance);
                            GenericModelDistance += MinDistance;

                            q[0, 0] = GenLeftCornerOfLips[0];
                            q[1, 0] = GenLeftCornerOfLips[1];
                            q[2, 0] = GenLeftCornerOfLips[2];
                            NewQ    = Roatation * q + Translation;
                            ClTools.FindClosestPointInModel(p_Model, (float)NewQ[0, 0], (float)NewQ[1, 0], (float)NewQ[2, 0], out closestPoint, out MinDistance);
                            GenericModelDistance += MinDistance;

                            q[0, 0] = GenRightCornerOfLips[0];
                            q[1, 0] = GenRightCornerOfLips[1];
                            q[2, 0] = GenRightCornerOfLips[2];
                            NewQ    = Roatation * q + Translation;
                            ClTools.FindClosestPointInModel(p_Model, (float)NewQ[0, 0], (float)NewQ[1, 0], (float)NewQ[2, 0], out closestPoint, out MinDistance);
                            GenericModelDistance += MinDistance;
                            // ----------


                            ClInformationSender.SendInformation("One of distances between generic model and face before thresholding: " + GenericModelDistance.ToString(System.Globalization.CultureInfo.InvariantCulture), ClInformationSender.eInformationType.eDebugText);

                            if (GenericModelDistance > m_fDistanceMinValueFromGenModel)
                            {
                                continue;
                            }

                            // Check if between eyes and nose there is other region (it should be not)

                            /*bool isBetweenNoseRegion = false;
                             * foreach (Cl3DModel.Cl3DModelPointIterator noseTmp in NoseTipsPoints)
                             * {
                             *  if (noseTmp.PointID == noseTip.PointID)
                             *      continue;
                             *
                             *  if (noseTmp.X > eyeLeft.X && noseTmp.X < eyeRight.X && noseTmp.Y > noseTip.Y && (noseTip.Y < eyeLeft.Y || noseTip.Y < eyeRight.Y))
                             *      isBetweenNoseRegion = true;
                             * }
                             * if (isBetweenNoseRegion)
                             *  continue;
                             */
                            List <Cl3DModel.Cl3DModelPointIterator> list = new List <Cl3DModel.Cl3DModelPointIterator>();
                            list.Add(noseTip);
                            list.Add(eyeLeft);
                            list.Add(eyeRight);

                            KeyValuePair <float, List <Cl3DModel.Cl3DModelPointIterator> > KeyVal = new KeyValuePair <float, List <Cl3DModel.Cl3DModelPointIterator> >(GenericModelDistance, list);

                            deltaOfDistanceBetweenModelAndPoints.Add(KeyVal);
                        }
                    }
                }
            }

            if (deltaOfDistanceBetweenModelAndPoints.Count == 0)
            {
                throw new Exception("Cannot find nose and eyes points");
            }

            float min = deltaOfDistanceBetweenModelAndPoints[0].Key;
            int   no  = 0;

            for (int i = 1; i < deltaOfDistanceBetweenModelAndPoints.Count; i++)
            {
                if (deltaOfDistanceBetweenModelAndPoints[i].Key < min)
                {
                    min = deltaOfDistanceBetweenModelAndPoints[i].Key;
                    no  = i;
                }
            }

            ClInformationSender.SendInformation("Correct MIN distance between generic model and face: " + min.ToString(System.Globalization.CultureInfo.InvariantCulture), ClInformationSender.eInformationType.eDebugText);

            p_Model.AddSpecificPoint(NameOfNoseTip, deltaOfDistanceBetweenModelAndPoints[no].Value[0]);
            p_Model.AddSpecificPoint(NameLeftEyeRightCorner, deltaOfDistanceBetweenModelAndPoints[no].Value[1]);
            p_Model.AddSpecificPoint(NameRightEyeLeftCorner, deltaOfDistanceBetweenModelAndPoints[no].Value[2]);
        }
        static void Main()
        {
            try
            {
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);

                // register all file formats
                Cl3DModel.RegisterReader(new ClAbsModelReader());
                Cl3DModel.RegisterReader(new ClWrmlModelReader());
                Cl3DModel.RegisterReader(new ClXYZModelReader());
                Cl3DModel.RegisterReader(new ClModelModelReader());
                Cl3DModel.RegisterReader(new ClBntModelReader());
                Cl3DModel.RegisterReader(new ClRifModelReader());
                Cl3DModel.RegisterReader(new ClMfileModelReader());
                Cl3DModel.RegisterReader(new ClOFFModelReader());
                Cl3DModel.RegisterReader(new ClOBJModelReader());
                Cl3DModel.RegisterReader(new ClPlyModelReader());
                Cl3DModel.RegisterReader(new ClDATModelReader());

                DxForm MainForm = new DxForm("3D Face Models Preprocessing Tool", "2.9");

                ClInformationSender.RegisterReceiver(new ClNewAlgorithmViewer(MainForm.TreeView), ClInformationSender.eInformationType.eNewAlgorithm); // add new algorithm watcher to add algoritms on form

                // register all algorithms to Algorithm Builder
                ClMapObjectAlgorithmBuilder.RegisterNewAlgorithm(ClLockModel.CrateAlgorithm, ClLockModel.ALGORITHM_NAME);
                ClMapObjectAlgorithmBuilder.RegisterNewAlgorithm(ClCheckIfCurvatureHasBeenCalculated.CrateAlgorithm, ClCheckIfCurvatureHasBeenCalculated.ALGORITHM_NAME);
                ClMapObjectAlgorithmBuilder.RegisterNewAlgorithm(ClCheckPointsPrecision.CrateAlgorithm, ClCheckPointsPrecision.ALGORITHM_NAME);

                ClMapObjectAlgorithmBuilder.RegisterNewAlgorithm(ClCalculateConformalParameterization.CrateAlgorithm, ClCalculateConformalParameterization.ALGORITHM_NAME);
                ClMapObjectAlgorithmBuilder.RegisterNewAlgorithm(ClNormalizeConformalMaps.CrateAlgorithm, ClNormalizeConformalMaps.ALGORITHM_NAME);
                ClMapObjectAlgorithmBuilder.RegisterNewAlgorithm(ClCalculateConformalFactor.CrateAlgorithm, ClCalculateConformalFactor.ALGORITHM_NAME);
                ClMapObjectAlgorithmBuilder.RegisterNewAlgorithm(ClConvertToUVParametrization.CrateAlgorithm, ClConvertToUVParametrization.ALGORITHM_NAME);
                ClMapObjectAlgorithmBuilder.RegisterNewAlgorithm(ClMobiusMapping.CrateAlgorithm, ClMobiusMapping.ALGORITHM_NAME);
                ClMapObjectAlgorithmBuilder.RegisterNewAlgorithm(ClRotateToPlaneCut.CrateAlgorithm, ClRotateToPlaneCut.ALGORITHM_NAME);


                ClMapObjectAlgorithmBuilder.RegisterNewAlgorithm(ClRemoveOneVertex.CrateAlgorithm, ClRemoveOneVertex.ALGORITHM_NAME);
                ClMapObjectAlgorithmBuilder.RegisterNewAlgorithm(ClRemoveSingleConnections.CrateAlgorithm, ClRemoveSingleConnections.ALGORITHM_NAME);
                ClMapObjectAlgorithmBuilder.RegisterNewAlgorithm(ClRemoveSmallUnconnectedParts.CrateAlgorithm, ClRemoveSmallUnconnectedParts.ALGORITHM_NAME);
                ClMapObjectAlgorithmBuilder.RegisterNewAlgorithm(ClRotatieModel.CrateAlgorithm, ClRotatieModel.ALGORITHM_NAME);
                ClMapObjectAlgorithmBuilder.RegisterNewAlgorithm(ClScaleModel.CrateAlgorithm, ClScaleModel.ALGORITHM_NAME);
                ClMapObjectAlgorithmBuilder.RegisterNewAlgorithm(ClMoveModel.CrateAlgorithm, ClMoveModel.ALGORITHM_NAME);
                ClMapObjectAlgorithmBuilder.RegisterNewAlgorithm(ClCorrectFacePose.CrateAlgorithm, ClCorrectFacePose.ALGORITHM_NAME);
                ClMapObjectAlgorithmBuilder.RegisterNewAlgorithm(ClRemoveRandomPartOfFace.CrateAlgorithm, ClRemoveRandomPartOfFace.ALGORITHM_NAME);
                ClMapObjectAlgorithmBuilder.RegisterNewAlgorithm(ClRemoveHalfOfTheFace.CrateAlgorithm, ClRemoveHalfOfTheFace.ALGORITHM_NAME);
                ClMapObjectAlgorithmBuilder.RegisterNewAlgorithm(ClRemovePathBetweenPoints.CrateAlgorithm, ClRemovePathBetweenPoints.ALGORITHM_NAME);
                ClMapObjectAlgorithmBuilder.RegisterNewAlgorithm(ClSetUnspecifiedPointTo.CrateAlgorithm, ClSetUnspecifiedPointTo.ALGORITHM_NAME);
                ClMapObjectAlgorithmBuilder.RegisterNewAlgorithm(ClRemoveAllLandmarks.CrateAlgorithm, ClRemoveAllLandmarks.ALGORITHM_NAME);
                ClMapObjectAlgorithmBuilder.RegisterNewAlgorithm(ClRemeshModel.CrateAlgorithm, ClRemeshModel.ALGORITHM_NAME);
                ClMapObjectAlgorithmBuilder.RegisterNewAlgorithm(ClRoundAllxyValuesSimplifyModel.CrateAlgorithm, ClRoundAllxyValuesSimplifyModel.ALGORITHM_NAME);
                ClMapObjectAlgorithmBuilder.RegisterNewAlgorithm(ClRoundUVvalues.CrateAlgorithm, ClRoundUVvalues.ALGORITHM_NAME);
                ClMapObjectAlgorithmBuilder.RegisterNewAlgorithm(ClCreateRegularGrid.CrateAlgorithm, ClCreateRegularGrid.ALGORITHM_NAME);
                ClMapObjectAlgorithmBuilder.RegisterNewAlgorithm(ClAddExpressionFRGC.CrateAlgorithm, ClAddExpressionFRGC.ALGORITHM_NAME);
                ClMapObjectAlgorithmBuilder.RegisterNewAlgorithm(ClCurvatureSubstractionFromTheSamePoints.CrateAlgorithm, ClCurvatureSubstractionFromTheSamePoints.ALGORITHM_NAME);
                ClMapObjectAlgorithmBuilder.RegisterNewAlgorithm(ClRemoveSpikesMedianFilter.CrateAlgorithm, ClRemoveSpikesMedianFilter.ALGORITHM_NAME);
                ClMapObjectAlgorithmBuilder.RegisterNewAlgorithm(ClRemoveSpikesGaussianFilter.CrateAlgorithm, ClRemoveSpikesGaussianFilter.ALGORITHM_NAME);
                ClMapObjectAlgorithmBuilder.RegisterNewAlgorithm(ClRemoveHoles.CrateAlgorithm, ClRemoveHoles.ALGORITHM_NAME);
                ClMapObjectAlgorithmBuilder.RegisterNewAlgorithm(ClRemoveHolesRangeImage.CrateAlgorithm, ClRemoveHolesRangeImage.ALGORITHM_NAME);
                ClMapObjectAlgorithmBuilder.RegisterNewAlgorithm(ClCurvaturesAndShapeIndexComputation.CrateAlgorithm, ClCurvaturesAndShapeIndexComputation.ALGORITHM_NAME);
                ClMapObjectAlgorithmBuilder.RegisterNewAlgorithm(ClCalculateCurvednessIndex.CrateAlgorithm, ClCalculateCurvednessIndex.ALGORITHM_NAME);
                ClMapObjectAlgorithmBuilder.RegisterNewAlgorithm(ClCalculateDistanceOnUVFrom3Points.CrateAlgorithm, ClCalculateDistanceOnUVFrom3Points.ALGORITHM_NAME);
                ClMapObjectAlgorithmBuilder.RegisterNewAlgorithm(ClCalculateDistanceOnXYZFrom3Points.CrateAlgorithm, ClCalculateDistanceOnXYZFrom3Points.ALGORITHM_NAME);
                ClMapObjectAlgorithmBuilder.RegisterNewAlgorithm(ClCalculateNormalVectors.CrateAlgorithm, ClCalculateNormalVectors.ALGORITHM_NAME);
                ClMapObjectAlgorithmBuilder.RegisterNewAlgorithm(ClCalculateUVExternalApp.CrateAlgorithm, ClCalculateUVExternalApp.ALGORITHM_NAME);
                ClMapObjectAlgorithmBuilder.RegisterNewAlgorithm(ClFindNoseTipAndEyesHKClassification.CrateAlgorithm, ClFindNoseTipAndEyesHKClassification.ALGORITHM_NAME);
                ClMapObjectAlgorithmBuilder.RegisterNewAlgorithm(ClFindNoseTipMaxVal.CrateAlgorithm, ClFindNoseTipMaxVal.ALGORITHM_NAME);
                ClMapObjectAlgorithmBuilder.RegisterNewAlgorithm(ClAddGenericModel.CrateAlgorithm, ClAddGenericModel.ALGORITHM_NAME);
                ClMapObjectAlgorithmBuilder.RegisterNewAlgorithm(ClAdjustAntropometryPoints.CrateAlgorithm, ClAdjustAntropometryPoints.ALGORITHM_NAME);
                ClMapObjectAlgorithmBuilder.RegisterNewAlgorithm(ClCropFaceBySphere.CrateAlgorithm, ClCropFaceBySphere.ALGORITHM_NAME);
                ClMapObjectAlgorithmBuilder.RegisterNewAlgorithm(ClCropFaceByGeodesicDistance.CrateAlgorithm, ClCropFaceByGeodesicDistance.ALGORITHM_NAME);
                ClMapObjectAlgorithmBuilder.RegisterNewAlgorithm(ClCropFaceEdge.CrateAlgorithm, ClCropFaceEdge.ALGORITHM_NAME);
                ClMapObjectAlgorithmBuilder.RegisterNewAlgorithm(ClCropFaceFrequencyFromTheNoseTip.CrateAlgorithm, ClCropFaceFrequencyFromTheNoseTip.ALGORITHM_NAME);
                ClMapObjectAlgorithmBuilder.RegisterNewAlgorithm(ClFaceMouth.CrateAlgorithm, ClFaceMouth.ALGORITHM_NAME);
                ClMapObjectAlgorithmBuilder.RegisterNewAlgorithm(ClCropByPlane.CrateAlgorithm, ClCropByPlane.ALGORITHM_NAME);
                ClMapObjectAlgorithmBuilder.RegisterNewAlgorithm(ClCropFaceGeodesicDistAndClosedLips.CrateAlgorithm, ClCropFaceGeodesicDistAndClosedLips.ALGORITHM_NAME);
                ClMapObjectAlgorithmBuilder.RegisterNewAlgorithm(ClCropEyesPart.CrateAlgorithm, ClCropEyesPart.ALGORITHM_NAME);
                ClMapObjectAlgorithmBuilder.RegisterNewAlgorithm(ClCropFaceSpecificValueLessThanThreshold.CrateAlgorithm, ClCropFaceSpecificValueLessThanThreshold.ALGORITHM_NAME);

                ClMapObjectAlgorithmBuilder.RegisterNewAlgorithm(ClLoadManualSpecificPoints.CrateAlgorithm, ClLoadManualSpecificPoints.ALGORITHM_NAME);
                ClMapObjectAlgorithmBuilder.RegisterNewAlgorithm(ClLoadAutomaticSpecificPoints.CrateAlgorithm, ClLoadAutomaticSpecificPoints.ALGORITHM_NAME);
                ClMapObjectAlgorithmBuilder.RegisterNewAlgorithm(ClLoadModelCurvaturesValues.CrateAlgorithm, ClLoadModelCurvaturesValues.ALGORITHM_NAME);
                ClMapObjectAlgorithmBuilder.RegisterNewAlgorithm(ClLoadPtsWithId.CrateAlgorithm, ClLoadPtsWithId.ALGORITHM_NAME);
                ClMapObjectAlgorithmBuilder.RegisterNewAlgorithm(ClLoadModelTextureFRGC.CrateAlgorithm, ClLoadModelTextureFRGC.ALGORITHM_NAME);
                ClMapObjectAlgorithmBuilder.RegisterNewAlgorithm(ClLoadLandmarksBosphourus.CrateAlgorithm, ClLoadLandmarksBosphourus.ALGORITHM_NAME);
                ClMapObjectAlgorithmBuilder.RegisterNewAlgorithm(ClLoadModelTextureBosphorus.CrateAlgorithm, ClLoadModelTextureBosphorus.ALGORITHM_NAME);
                ClMapObjectAlgorithmBuilder.RegisterNewAlgorithm(ClLoadXiangManual.CrateAlgorithm, ClLoadXiangManual.ALGORITHM_NAME);
                ClMapObjectAlgorithmBuilder.RegisterNewAlgorithm(ClLoadGavabManual.CrateAlgorithm, ClLoadGavabManual.ALGORITHM_NAME);

                ClMapObjectAlgorithmBuilder.RegisterNewAlgorithm(ClSaveModel.CrateAlgorithm, ClSaveModel.ALGORITHM_NAME);
                ClMapObjectAlgorithmBuilder.RegisterNewAlgorithm(ClSaveModelToObj.CrateAlgorithm, ClSaveModelToObj.ALGORITHM_NAME);
                ClMapObjectAlgorithmBuilder.RegisterNewAlgorithm(ClSaveModelToMFile.CrateAlgorithm, ClSaveModelToMFile.ALGORITHM_NAME);
                ClMapObjectAlgorithmBuilder.RegisterNewAlgorithm(ClSaveToMFileNew.CrateAlgorithm, ClSaveToMFileNew.ALGORITHM_NAME);
                ClMapObjectAlgorithmBuilder.RegisterNewAlgorithm(ClSaveSpecificPointsCoordinates.CrateAlgorithm, ClSaveSpecificPointsCoordinates.ALGORITHM_NAME);
                ClMapObjectAlgorithmBuilder.RegisterNewAlgorithm(ClSaveManualLandmarks.CrateAlgorithm, ClSaveManualLandmarks.ALGORITHM_NAME);
                ClMapObjectAlgorithmBuilder.RegisterNewAlgorithm(ClSaveSpecificPointsWithIDs.CrateAlgorithm, ClSaveSpecificPointsWithIDs.ALGORITHM_NAME);
                ClMapObjectAlgorithmBuilder.RegisterNewAlgorithm(ClSaveModelCurvaturesValues.CrateAlgorithm, ClSaveModelCurvaturesValues.ALGORITHM_NAME);
                ClMapObjectAlgorithmBuilder.RegisterNewAlgorithm(ClSaveObjectBitmap.CrateAlgorithm, ClSaveObjectBitmap.ALGORITHM_NAME);
                ClMapObjectAlgorithmBuilder.RegisterNewAlgorithm(ClRasterizeModel.CrateAlgorithm, ClRasterizeModel.ALGORITHM_NAME);
                ClMapObjectAlgorithmBuilder.RegisterNewAlgorithm(ClSaveNoseTipXYandEyesAngle.CrateAlgorithm, ClSaveNoseTipXYandEyesAngle.ALGORITHM_NAME);
                ClMapObjectAlgorithmBuilder.RegisterNewAlgorithm(ClSaveRotationAndTranslationToGenModel.CrateAlgorithm, ClSaveRotationAndTranslationToGenModel.ALGORITHM_NAME);

                ClMapObjectAlgorithmBuilder.RegisterNewAlgorithm(ClShowHKClassification.CrateAlgorithm, ClShowHKClassification.ALGORITHM_NAME);
                ClMapObjectAlgorithmBuilder.RegisterNewAlgorithm(ClShowNoseRegions.CrateAlgorithm, ClShowNoseRegions.ALGORITHM_NAME);
                ClMapObjectAlgorithmBuilder.RegisterNewAlgorithm(ClShowEyesRegions.CrateAlgorithm, ClShowEyesRegions.ALGORITHM_NAME);
                ClMapObjectAlgorithmBuilder.RegisterNewAlgorithm(ClColorModelSpecificValue.CrateAlgorithm, ClColorModelSpecificValue.ALGORITHM_NAME);
                ClMapObjectAlgorithmBuilder.RegisterNewAlgorithm(ClColorMainPointsNeighborhood.CrateAlgorithm, ClColorMainPointsNeighborhood.ALGORITHM_NAME);
                ClMapObjectAlgorithmBuilder.RegisterNewAlgorithm(ClColorNoseTipNeighborhood.CrateAlgorithm, ClColorNoseTipNeighborhood.ALGORITHM_NAME);
                ClMapObjectAlgorithmBuilder.RegisterNewAlgorithm(ClColorGeometryImage.CrateAlgorithm, ClColorGeometryImage.ALGORITHM_NAME);
                ClMapObjectAlgorithmBuilder.RegisterNewAlgorithm(ClColorModelNormalVectors.CrateAlgorithm, ClColorModelNormalVectors.ALGORITHM_NAME);

                ClMapObjectAlgorithmBuilder.RegisterNewAlgorithm(ClDoSomething.CrateAlgorithm, ClDoSomething.ALGORITHM_NAME);

                ClMapObjectAlgorithmBuilder.RegisterNewAlgorithm(ClOrganizeFolders.CrateAlgorithm, ClOrganizeFolders.ALGORITHM_NAME);
                ClMapObjectAlgorithmBuilder.RegisterNewAlgorithm(ClOrganizeFoldersByExpression.CrateAlgorithm, ClOrganizeFoldersByExpression.ALGORITHM_NAME);
                //-----------------------------------------------------

                Application.Run(MainForm);
#if RENDER_1
                ClRender.getInstance().StopRendering();
#endif
                ClFasadaPreprocessing.ResetFasade();
            }
            catch (Exception e)
            {
#if RENDER_1
                ClRender.getInstance().StopRendering();
#endif
                if (MessageBox.Show("Unexpected error: " + e.Message + "\nRestart the application?", "Exception", MessageBoxButtons.YesNo, MessageBoxIcon.Error) == DialogResult.Yes)
                {
                    Application.Restart();
                }
                else
                {
                    Application.Exit();
                }
            }
        }
Esempio n. 30
0
        protected override void Algorithm(ref Cl3DModel p_Model)
        {
            Cl3DModel.Cl3DModelPointIterator iter = p_Model.GetIterator();

            if (!iter.IsValid())
            {
                throw new Exception("Iter is not valid");
            }

            if (m_ResetColor)
            {
                do
                {
                    iter.Color = Color.White;
                } while (iter.MoveToNext());
                return;
            }

            if (!m_bMinMaxPreset)
            {
                bool firstTime = true;
                do
                {
                    double Value;

                    if (m_RangeColor)
                    {
                        Value = iter.Z;
                    }
                    else if (!iter.GetSpecificValue(m_SpecificValue, out Value))
                    {
                        continue;
                    }

                    if (firstTime)
                    {
                        m_dMaxValue = Value;
                        m_dMinValue = Value;
                        firstTime   = false;
                        continue;
                    }

                    if (Value > m_dMaxValue)
                    {
                        m_dMaxValue = Value;
                    }
                    if (Value < m_dMinValue)
                    {
                        m_dMinValue = Value;
                    }
                } while (iter.MoveToNext());
            }


            if (m_SpecificValue.Contains("ShapeIndex") && !m_RangeColor)
            {
                m_dMinValue = 0;
                m_dMaxValue = 1;
            }


            if (m_bMaxMinFromNoseAndEyes)
            {
                Cl3DModel.Cl3DModelPointIterator        NoseTip          = p_Model.GetSpecificPoint(Cl3DModel.eSpecificPoints.NoseTip);
                List <Cl3DModel.Cl3DModelPointIterator> NeighborhoodNose = null;
                ClTools.GetNeighborhoodWithGeodesicDistance(out NeighborhoodNose, NoseTip, 10f);

                if (m_sMinValuePointName.Equals("Nose"))
                {
                    m_dMinValue = NoseTip.GetSpecificValue(m_SpecificValue);
                    foreach (Cl3DModel.Cl3DModelPointIterator nb in NeighborhoodNose)
                    {
                        double currVal = nb.GetSpecificValue(m_SpecificValue);
                        if (currVal < m_dMinValue)
                        {
                            m_dMinValue = currVal;
                        }
                    }
                }
                else if (m_sMaxValuePointName.Equals("Nose"))
                {
                    m_dMaxValue = NoseTip.GetSpecificValue(m_SpecificValue);
                    foreach (Cl3DModel.Cl3DModelPointIterator nb in NeighborhoodNose)
                    {
                        double currVal = nb.GetSpecificValue(m_SpecificValue);
                        if (currVal > m_dMaxValue)
                        {
                            m_dMaxValue = currVal;
                        }
                    }
                }
                NeighborhoodNose = null;

                Cl3DModel.Cl3DModelPointIterator        Eye1             = p_Model.GetSpecificPoint(Cl3DModel.eSpecificPoints.LeftEyeRightCorner);
                Cl3DModel.Cl3DModelPointIterator        Eye2             = p_Model.GetSpecificPoint(Cl3DModel.eSpecificPoints.RightEyeLeftCorner);
                List <Cl3DModel.Cl3DModelPointIterator> NeighborhoodEye1 = null;
                List <Cl3DModel.Cl3DModelPointIterator> NeighborhoodEye2 = null;
                ClTools.GetNeighborhoodWithGeodesicDistance(out NeighborhoodEye1, Eye1, 10f);
                ClTools.GetNeighborhoodWithGeodesicDistance(out NeighborhoodEye2, Eye2, 10f);

                NeighborhoodEye1.Add(Eye2);
                foreach (Cl3DModel.Cl3DModelPointIterator ne in NeighborhoodEye2)
                {
                    NeighborhoodEye1.Add(ne);
                }


                if (m_sMinValuePointName.Equals("Eye"))
                {
                    m_dMinValue = Eye1.GetSpecificValue(m_SpecificValue);
                    foreach (Cl3DModel.Cl3DModelPointIterator nb in NeighborhoodEye1)
                    {
                        double currVal = nb.GetSpecificValue(m_SpecificValue);
                        if (currVal < m_dMinValue)
                        {
                            m_dMinValue = currVal;
                        }
                    }
                }
                else if (m_sMaxValuePointName.Equals("Eye"))
                {
                    m_dMaxValue = Eye1.GetSpecificValue(m_SpecificValue);
                    foreach (Cl3DModel.Cl3DModelPointIterator nb in NeighborhoodEye1)
                    {
                        double currVal = nb.GetSpecificValue(m_SpecificValue);
                        if (currVal > m_dMaxValue)
                        {
                            m_dMaxValue = currVal;
                        }
                    }
                }
            }

            iter = p_Model.GetIterator();
            do
            {
                double Value;
                if (m_RangeColor)
                {
                    Value = iter.Z;
                }
                else if (!iter.GetSpecificValue(m_SpecificValue, out Value))
                {
                    continue;
                }


                double divide = 1;
                if (m_dMaxValue != m_dMinValue)
                {
                    divide = (m_dMaxValue - m_dMinValue);
                }

                if (m_Color == ColorType.RGB)
                {
                    iter.Color = ClTools.GetColorRGB((float)((Value - m_dMinValue) / divide), 1.0f);
                }
                else if (m_Color == ColorType.Gray)
                {
                    iter.Color = ClTools.GetColorGray((float)((Value - m_dMinValue) / divide), 1.0f);
                }
                else if (m_Color == ColorType.R)
                {
                    Color PartialColor = ClTools.GetColorRGB((float)((Value - m_dMinValue) / divide), 1.0f);

                    int R = 0; R = (R << 8) + (int)PartialColor.R;
                    int G = 0; G = (G << 8) + (int)PartialColor.G;
                    int B = 0; B = (B << 8) + (int)PartialColor.B;

                    Color newColor = Color.FromArgb((R + G + B) / 3, iter.Color.G, iter.Color.B);

                    iter.Color = newColor;
                }
                else if (m_Color == ColorType.G)
                {
                    Color PartialColor = ClTools.GetColorRGB((float)((Value - m_dMinValue) / divide), 1.0f);

                    int R = 0; R = (R << 8) + (int)PartialColor.R;
                    int G = 0; G = (G << 8) + (int)PartialColor.G;
                    int B = 0; B = (B << 8) + (int)PartialColor.B;

                    Color newColor = Color.FromArgb(iter.Color.R, (R + G + B) / 3, iter.Color.B);
                    iter.Color = newColor;
                }
                else if (m_Color == ColorType.B)
                {
                    Color PartialColor = ClTools.GetColorRGB((float)((Value - m_dMinValue) / divide), 1.0f);

                    int R = 0; R = (R << 8) + (int)PartialColor.R;
                    int G = 0; G = (G << 8) + (int)PartialColor.G;
                    int B = 0; B = (B << 8) + (int)PartialColor.B;

                    Color newColor = Color.FromArgb(iter.Color.R, iter.Color.G, (R + G + B) / 3);
                    iter.Color = newColor;
                }
            } while (iter.MoveToNext());
            ClInformationSender.SendInformation(m_SpecificValue.ToString() + " Max: " + m_dMaxValue.ToString() + " Min: " + m_dMinValue.ToString(), ClInformationSender.eInformationType.eColorMapChanged);
        }