Exemplo n.º 1
0
        private static void InterpolationComparison()
        {
            string       filepath  = "D:/Users/yrmal/Desktop/doublegyro";
            double       voxelSize = 0.25;
            InputDataSet ids       = new InputDataSet(filepath, voxelSize, null);
            double       xMax      = 2;
            double       yMax      = 1;
            double       step      = 0.01;

            Point[,] matrix = new Point[(int)(xMax / step), (int)(yMax / step)];

            for (int x = 0; x < xMax / step; x++)
            {
                for (int y = 0; y < yMax / step; y++)
                {
                    matrix[x, y] = Interpolator <Point> .NNInterpolatePoint(new Vector3((float)(x * step), (float)(y * step), 0), ids.GetPoints());
                }
            }
            int pointSize = sizeof(float) * 6;

            byte[] serialized = new byte[matrix.Length * pointSize];
            int    i          = 0;

            foreach (Point p in matrix)
            {
                if (p != null)
                {
                    Array.Copy(p.Serialize(), 0, serialized, i * pointSize, pointSize);
                }
                i++;
            }
            using (FileStream fileStream = new FileStream("./NN.dat", FileMode.Create))
            {
                fileStream.Write(serialized, 0, serialized.Length);
            }



            for (int x = 0; x < xMax / step; x++)
            {
                for (int y = 0; y < yMax / step; y++)
                {
                    matrix[x, y] = ids.GetPoint(new Vector3((float)(x * step), (float)(y * step), 0));
                }
            }
            serialized = new byte[matrix.Length * pointSize];
            i          = 0;
            foreach (Point p in matrix)
            {
                if (p != null)
                {
                    Array.Copy(p.Serialize(), 0, serialized, i * pointSize, pointSize);
                }
                i++;
            }
            using (FileStream fileStream = new FileStream("./IDW.dat", FileMode.Create))
            {
                fileStream.Write(serialized, 0, serialized.Length);
            }
        }
Exemplo n.º 2
0
        private void MakeCalculations(object sender, DoWorkEventArgs e)
        {
            List <Thread>    threads;
            ManualResetEvent notifier = new ManualResetEvent(false);
            BackgroundWorker worker   = sender as BackgroundWorker;

            worker.ReportProgress(0);
            Debug.WriteLine("Start doing work!");
            sls = new StreamLines();
            Advection adv = new Advection(ids, sls);
            // start advection routine
            float        radius      = float.Parse(this.avDistance.Text) / 2;
            int          steps       = int.Parse(this.steps.Text);
            double       dt          = double.Parse(this.dt.Text);
            List <Point> entryPoints = new List <Point>();
            int          segments    = 20; //segments => points = segments - 1 + end_point //TODO

            foreach (List <Point> line in picture.Lines)
            {
                Point last = null;
                foreach (Point p in line)
                {
                    if (last != null)
                    {
                        //interpolate a line
                        for (int i = 1; i < segments; i++)
                        {
                            float   ratio = (float)i / segments;
                            Vector3 pos   = new Vector3(
                                ((p.Pos.X - last.Pos.X) * ratio) + last.Pos.X,
                                ((p.Pos.Y - last.Pos.Y) * ratio) + last.Pos.Y,
                                ((p.Pos.Z - last.Pos.Z) * ratio) + last.Pos.Z
                                );
                            entryPoints.Add(ids.GetPoint(pos));
                        }
                    }
                    entryPoints.Add(p);
                    last = p;
                }
            }
            Debug.WriteLine("N-points: " + entryPoints.Count);
            threads = adv.Start(radius, steps, dt, dir, entryPoints, 40, notifier, worker);             //TODO

            Debug.WriteLine("Threads are creared, waiting untilthey all die");
            int threadMax = threads.Count;

            worker.ReportProgress(0);
            while (threads.Count > 0)
            {
                notifier.WaitOne(2000);
                notifier.Reset();
                foreach (Thread t in threads.ToList())
                {
                    if (!t.IsAlive)
                    {
                        threads.Remove(t);
                    }
                }
                worker.ReportProgress((threadMax - threads.Count) * 1000 / threadMax);
            }

            worker.ReportProgress(0);
            Debug.WriteLine("StreamLines were calculated");
            Debug.WriteLine("Start creating uniform FTLE field");
            int       resolution = int.Parse(this.resolution.Text);
            FTLEField field      = new FTLEField(ids, resolution);

            threads   = field.PrepareField(notifier, sls, 40);
            threadMax = threads.Count;
            while (threads.Count > 0)
            {
                notifier.WaitOne(2000);
                notifier.Reset();
                foreach (Thread t in threads.ToList())
                {
                    if (!t.IsAlive)
                    {
                        threads.Remove(t);
                    }
                }
                worker.ReportProgress((threadMax - threads.Count) * 1000 / threadMax);
                Debug.WriteLine("threads.Count " + threads.Count + " Max " + threadMax +
                                " Fraction " + ((threadMax - threads.Count) * 1000 / threadMax) + "/" + 1000);
            }

            worker.ReportProgress(0);
            threads = field.Start(notifier, resolution, 40);
            Debug.WriteLine("Threads are done, waiting for their end");
            threadMax = threads.Count;
            while (threads.Count > 0)
            {
                notifier.WaitOne(2000);
                notifier.Reset();
                foreach (Thread t in threads.ToList())
                {
                    if (!t.IsAlive)
                    {
                        threads.Remove(t);
                    }
                }
                worker.ReportProgress((threadMax - threads.Count) * 1000 / threadMax);
                Debug.WriteLine("threads.Count " + threads.Count + " Max " + threadMax +
                                " Fraction " + ((threadMax - threads.Count) * 1000 / threadMax) + "/" + 1000);
            }

            worker.ReportProgress(0);
            field.CreateSquares(resolution, worker);
            field.Serialize(selectOutputFolderDialog.SelectedPath, worker);
            Debug.WriteLine("All done!");
        }