Exemplo n.º 1
0
        public void TestMapping()
        {
            // Referenční soubor
            IFileReader            fileReader  = new ObjFileReader("");
            List <Vector <float> > referPoints = fileReader.ReadVertices();

            // Zdrojový soubor
            fileReader = new ObjFileReader("");
            List <Vector <float> > sourcePoints = fileReader.ReadVertices();

            // Doplnit maximální vzdálenost
            IPointMapping          bruteForceMapping      = new BruteForceMapping(referPoints, 50f);
            List <Vector <float> > bruteForceMappedPoints = bruteForceMapping.MapPoints(sourcePoints, out List <Vector <float> > mappedSourcePoints);

            // Doplnit maximální vzdálenost
            IPointMapping          kdMapping      = new KdTreeMapping(referPoints, 50f);
            List <Vector <float> > kdMappedPoints = kdMapping.MapPoints(sourcePoints, out mappedSourcePoints);

            Assert.AreEqual(bruteForceMappedPoints.Count, kdMappedPoints.Count);

            bool allEqual = true;

            for (int i = 0; i < bruteForceMappedPoints.Count; i++)
            {
                if (!bruteForceMappedPoints[i].Equals(kdMappedPoints[i]))
                {
                    allEqual = false;
                    break;
                }
            }

            Assert.IsTrue(allEqual);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Starts a worker on the background. It compresses given files and creates a new compressed .3gbf file from them.
        /// </summary>
        /// <param name="sender">Sender of the event.</param>
        /// <param name="e">Arguments of the event.</param>
        private void BackgroundWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            Log.Info("Background worker starts.");
            Log.Debug("Background worker argument: " + (int)e.Argument);

            Compression compression = new Compression();

            for (int i = 0; i < this.listFiles.CheckedItems.Count; i++)
            {
                string path = (string)this.listFiles.CheckedItems[i];
                Log.Debug("Path of a file: " + path);

                try
                {
                    IFileReader fileReader = new ObjFileReader(path);
                    if (compression.FramesCount != 0)
                    {
                        compression.AddFrame(fileReader.ReadVertices());
                    }
                    else
                    {
                        compression.AddFrame(fileReader.ReadAll());
                    }
                }
                catch (IOException ex)
                {
                    Log.Error("Unable to read " + path + ". " + ex.Message);
                    CompressionForm.statusBar.Text = "Unable to read " + path + ".";
                }
                finally
                {
                    this.backgroundWorker.ReportProgress(i + 1);
                }
            }

            compression.CompressFrames((int)e.Argument);

            try
            {
                FileWriter writer = new FileWriter(string.Format(@"3DAnimation{0}.3ba", DateTime.Now.Ticks));
                writer.WriteTrajectory(compression.AverageTrajectory);
                writer.WriteEigenVectors(compression.SubEigenVectors);
                writer.WriteControlTrajectories(compression.ControlTrajectories);
                writer.WriteFaces(compression.Frame.Faces);
                writer.WriteTextures(compression.Frame.TextureCoords);
                writer.Close();
            } catch (Exception ex)
            {
                Log.Error("Cannot write to a file. " + ex.Message);
                statusBar.Text = "Error during writing to the file. Compression failed.";
            }
        }