Ejemplo n.º 1
0
        private static void Main(string[] args)
        {
            var    dir       = new DirectoryInfo("../../../../TestFiles");
            var    fileNames = dir.GetFiles();
            string filename  = "";

            for (var i = 0; i < fileNames.Count(); i++)
            {
                try
                {
                    filename = fileNames[i].FullName;
                    Console.WriteLine("Attempting: " + filename);
                    List <DefaultVertex> vertices;
                    var v3D        = MakeModelVisual3D(filename, out vertices);
                    var now        = DateTime.Now;
                    var convexHull = ConvexHull.Create(vertices);
                    var interval   = DateTime.Now - now;
                    Window3DPlot.ShowWithConvexHull(v3D, convexHull);
                    Console.WriteLine("time = " + interval);
                }
                catch (Exception e)
                {
                    Console.WriteLine("Failed on " + filename + ": " + e.Message);
                }
            }
            Console.ReadLine();
        }
Ejemplo n.º 2
0
        internal static void ShowWithConvexHull(Visual3D v3D, ConvexHull <DefaultVertex, DefaultConvexFace <DefaultVertex> > convexHull)
        {
            var window = new Window3DPlot();

            window.view1.Children.Add(v3D);
            var positions =
                convexHull.Faces.SelectMany(
                    f => f.Vertices.Select(v => new Point3D(v.Position[0], v.Position[1], v.Position[2])));
            var normals =
                convexHull.Faces.SelectMany(f => f.Vertices.Select(v => new Vector3D(f.Normal[0], f.Normal[1], f.Normal[2])));

            window.view1.Children.Add(
                new ModelVisual3D
            {
                Content =
                    new GeometryModel3D
                {
                    Geometry = new MeshGeometry3D
                    {
                        Positions = new Point3DCollection(positions),
                        // TriangleIndices = new Int32Collection(triIndices),
                        Normals = new Vector3DCollection(normals)
                    },
                    Material = MaterialHelper.CreateMaterial(new System.Windows.Media.Color {
                        A = 130, G = 189, R = 189
                    })
                }
            });
            window.view1.FitView(window.view1.Camera.LookDirection, window.view1.Camera.UpDirection);
            //window.Show();
            window.ShowDialog();
        }