Ejemplo n.º 1
0
        private void ButtonRBF_Click(object sender, RoutedEventArgs e)
        {
            bool rc = _scol.BuildSortedSlicesArray();

            if (!rc)
            {
                System.Windows.MessageBox.Show("There are skips in CTs!");
                return;
            }

            int nz = _scol.Slices.Length;

            int nr = _scol.Slices[0].RowCount;
            int nc = _scol.Slices[0].ColumnCount;

            // Create Volume for Structure
            byte[][,] mask = MakeMask(nz, nr, nc);

            Point3f[]         points = _ccol.Flatten();
            Evaluator.InOut[] inout  = new Evaluator.InOut[points.Length];
            for (int k = 0; k != inout.Length; ++k)
            {
                inout[k] = (k == inout.Length - 1) ? Evaluator.InOut.IN : Evaluator.InOut.BND;
            }

            EvaluatorRBF eval = new EvaluatorRBF(points, inout);

            eval.Evaluate(new Point3f(0.0f, 0.0f, 0.0f));
            float[] weights = eval.Weights;

            Point3D shift = _ccol.Shift;

            for (int iz = (int)shift.Z - 6; iz != (int)shift.Z + 6; ++iz)
            {
                float z = (float)iz + 0.5f;

                byte[,] plane = mask[iz];
                for (int r = 0; r != nr; ++r)
                {
                    float x = (float)r + 0.5f;
                    for (int c = 0; c != nc; ++c)
                    {
                        float y = (float)c + 0.5f;

                        float q = eval.Evaluate(new Point3f(x - (float)shift.X, y - (float)shift.Y, z - (float)shift.Z));

                        if (q > -0.01f)
                        {
                            plane[r, c] = 1;
                        }
                    }
                }
            }

            CreateMaskedVolumeView(+500, mask, _scol.Slices);
        }
Ejemplo n.º 2
0
        static void TestSphere(string fname)
        {
            // this is simple sphere test, 6 points at boundaries and one in the center
            Tuple <Point3f[], float[]> tu = ReadFile(fname);

            Point3f[] points  = tu.Item1;
            float[]   weights = tu.Item2;

            Evaluator.InOut[] inout = new Evaluator.InOut[points.Length];

            // for this file, only point in center is inside
            for (int k = 0; k != inout.Length; ++k)
            {
                inout[k] = Evaluator.InOut.BND;
                if (points[k].X == 0.0f && points[k].Y == 0.0f && points[k].Z == 0.0f)
                {
                    inout[k] = Evaluator.InOut.IN;
                }
            }

            EvaluatorRBF eval = new EvaluatorRBF(points, inout, null /*weights*/);

            eval.Evaluate(points[0]);

            float[] new_weights = eval.Weights;

            Console.WriteLine("Stored weights vs Computed weights");
            for (int k = 0; k != new_weights.Length; ++k)
            {
                Console.WriteLine(String.Format("Stored weight: {0}   Computed weight: {1}", weights[k], new_weights[k]));
            }
            Console.WriteLine("");

            // self-test
            // each original point shall be classified properly
            Console.WriteLine("Original points classification");
            for (int k = 0; k != points.Length; ++k)
            {
                float d = eval.Evaluate(points[k]);
                Console.WriteLine(String.Format("Original class: {0}  Computed class: {1}", (float)inout[k], d));
            }
            Console.WriteLine("");

            for (int iz = -6; iz != 7; ++iz)
            {
                float z = (float)iz * 1.0f;
                for (int r = -6; r != 7; ++r)
                {
                    float y = (float)r * 1.0f;
                    for (int c = -6; c != 7; ++c)
                    {
                        float x = (float)c * 1.0f;

                        float d = eval.Evaluate(new Point3f(x, y, z));

                        Console.Write(d);
                        Console.Write("  ");
                    }
                    Console.WriteLine("");
                }
            }
            Console.WriteLine("");
        }