예제 #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void RotationGraph_Click(object sender, EventArgs e)
        {
            OpenFileDialog dlg = new OpenFileDialog();

            dlg.Filter           = "Gestures (*.xml)|*.xml";
            dlg.Title            = "Load Gesture Pairs";
            dlg.Multiselect      = true;
            dlg.RestoreDirectory = false;

            if (dlg.ShowDialog(this) == DialogResult.OK)
            {
                if (dlg.FileNames.Length % 2 != 0)
                {
                    MessageBox.Show(this, "Pairs of two gestures must be selected.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else
                {
                    FolderBrowserDialog fld = new FolderBrowserDialog();
                    fld.Description  = "Select a folder where the results file will be written.";
                    fld.SelectedPath = dlg.FileName.Substring(0, dlg.FileName.LastIndexOf('\\'));
                    if (fld.ShowDialog() == DialogResult.OK)
                    {
                        string[] filenames = new string[dlg.FileNames.Length];
                        Array.Copy(dlg.FileNames, filenames, dlg.FileNames.Length);

                        Array.Sort(filenames); // sorts alphabetically
                        if (!_similar)         // doing rotation graphs for dissimilar gestures
                        {
                            bool dissimilar = false;
                            while (!dissimilar)
                            {
                                for (int j = 0; j < filenames.Length * 2; j++) // random shuffle
                                {
                                    int    pos1 = RandomEx.Integer(0, filenames.Length - 1);
                                    int    pos2 = RandomEx.Integer(0, filenames.Length - 1);
                                    string tmp  = filenames[pos1];
                                    filenames[pos1] = filenames[pos2];
                                    filenames[pos2] = tmp;
                                }
                                for (int j = 0; j < filenames.Length; j += 2) // ensure no pairs are same category
                                {
                                    string cat1 = Category.ParseName(Unistroke.ParseName(filenames[j + 1]));
                                    string cat2 = Category.ParseName(Unistroke.ParseName(filenames[j]));
                                    dissimilar = (cat1 != cat2); // set the flag
                                    if (!dissimilar)
                                    {
                                        break;
                                    }
                                }
                            }
                        }

                        // now do the rotating and declare victory
                        bool failed = false;
                        for (int i = 0; i < filenames.Length; i += 2)
                        {
                            if (!_rec.CreateRotationGraph(filenames[i + 1], filenames[i], fld.SelectedPath, _similar))
                            {
                                MessageBox.Show(this, "There was an error reading or writing files.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                failed = true;
                            }
                        }
                        if (!failed)
                        {
                            MessageBox.Show(this, "Finished rotations of gesture pair(s).", "Complete", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                    }
                }
            }
        }