示例#1
0
        public void Load(string fileName)
        {
            var probing = DataContext as ProbingViewModel;

            probing.HeightMap.HasHeightMap = false;
            probing.HeightMap.Map          = HeightMap.Load(fileName);
            probing.HeightMap.GridSize     = probing.HeightMap.Map.GridX;
            probing.HeightMap.MinX         = probing.HeightMap.Map.Min.X;
            probing.HeightMap.MinY         = probing.HeightMap.Map.Min.Y;
            probing.HeightMap.MaxX         = probing.HeightMap.Map.Max.X;
            probing.HeightMap.MaxY         = probing.HeightMap.Map.Max.Y;

            LinesVisual3D        boundary  = new LinesVisual3D();
            PointsVisual3D       mapPoints = new PointsVisual3D();
            MeshGeometryVisual3D mesh      = new MeshGeometryVisual3D();

            // TODO: fix HeightMap object...
            probing.HeightMap.Map.GetModel(mesh);
            probing.HeightMap.Map.GetPreviewModel(boundary, mapPoints);

            probing.HeightMap.MeshGeometry   = mesh.MeshGeometry;
            probing.HeightMap.BoundaryPoints = boundary.Points;
            probing.HeightMap.MapPoints      = mapPoints.Points;
            probing.HeightMap.HasHeightMap   = true;
        }
示例#2
0
        public void GetModel(MeshGeometryVisual3D mesh)
        {
            MeshBuilder mb = new MeshBuilder(false, true);

            double Hdelta = MaxHeight - MinHeight;

            for (int x = 0; x < SizeX - 1; x++)
            {
                for (int y = 0; y < SizeY - 1; y++)
                {
                    if (!Points[x, y].HasValue || !Points[x, y + 1].HasValue || !Points[x + 1, y].HasValue || !Points[x + 1, y + 1].HasValue)
                    {
                        continue;
                    }

                    mb.AddQuad(
                        new Point3D(Min.X + (x + 1) * Delta.X / (SizeX - 1), Min.Y + (y) * Delta.Y / (SizeY - 1), Points[x + 1, y].Value),
                        new Point3D(Min.X + (x + 1) * Delta.X / (SizeX - 1), Min.Y + (y + 1) * Delta.Y / (SizeY - 1), Points[x + 1, y + 1].Value),
                        new Point3D(Min.X + (x) * Delta.X / (SizeX - 1), Min.Y + (y + 1) * Delta.Y / (SizeY - 1), Points[x, y + 1].Value),
                        new Point3D(Min.X + (x) * Delta.X / (SizeX - 1), Min.Y + (y) * Delta.Y / (SizeY - 1), Points[x, y].Value),
                        new Point(0, (Points[x + 1, y].Value - MinHeight) * Hdelta),
                        new Point(0, (Points[x + 1, y + 1].Value - MinHeight) * Hdelta),
                        new Point(0, (Points[x, y + 1].Value - MinHeight) * Hdelta),
                        new Point(0, (Points[x, y].Value - MinHeight) * Hdelta)
                        );
                }
            }

            mesh.MeshGeometry = mb.ToMesh();
        }
示例#3
0
        public void changeSTLModel(String filename)
        {
            viewPort3d.Children.Add(obj);
            MeshGeometryVisual3D newObj = new MeshGeometryVisual3D();

            newObj.Content = Display3d(filename);
        }
示例#4
0
        public void Wpf_Export_Triangle_Valid()
        {
            var b1 = new MeshBuilder();

            b1.AddTriangle(new Point3D(0, 0, 0), new Point3D(0, 0, 1), new Point3D(0, 1, 0));
            var meshGeometry = b1.ToMesh();

            var mesh = new MeshGeometryVisual3D();

            mesh.MeshGeometry = meshGeometry;
            mesh.Material     = Materials.Green;
            mesh.Transform    = new TranslateTransform3D(2, 0, 0);

            var viewport = new HelixViewport3D();

            viewport.Items.Add(mesh);

            string temp    = Path.GetTempPath();
            var    objPath = temp + "model.obj";
            var    mtlPath = temp + "model.mtl";

            try
            {
                viewport.Export(objPath);

                string contentObj  = File.ReadAllText(objPath);
                string expectedObj = @"mtllib ./model.mtl
o object1
g group1
usemtl mat1
v 2 0 0
v 2 0 1
v 2 1 0
# 3 vertices
vt 0 1
vt 1 1
vt 0 0
# 3 texture coordinates
f 1/1 2/2 3/3
# 1 faces

";

                Assert.AreEqual(expectedObj.Replace("\r\n", "\n"), contentObj.Replace("\r\n", "\n"));

                string contentMtl = File.ReadAllText(mtlPath);
            }
            finally
            {
                if (File.Exists(objPath))
                {
                    File.Delete(objPath);
                }

                if (File.Exists(mtlPath))
                {
                    File.Delete(mtlPath);
                }
            }
        }
        /// <summary>
        /// Create a MeshGeometryVisual3D from an existing HalfEdgeMesh with specified Colors.
        /// </summary>
        /// <param name="mesh">The existing HalfEdgeMesh.</param>
        /// <param name="foreground">The Color for the Triangles of the Mesh.</param>
        /// <param name="backGround">The Background Color for the Triangles of the Mesh.</param>
        /// <returns>MeshGeometryVisual3D of the HalfEdgeMesh with the specified Materials.</returns>
        private static MeshGeometryVisual3D CreateVisual3DWithNormals(this HalfEdgeMesh mesh,
                                                                      Material frontMaterial, Material backMaterial)
        {
            if (frontMaterial == default(Material))
            {
                frontMaterial = new DiffuseMaterial(new SolidColorBrush(DefaultForegroundColor));
            }
            if (backMaterial == default(Material))
            {
                backMaterial = new DiffuseMaterial(new SolidColorBrush(DefaultBackgroundColor));
            }

            var mesh3D = new MeshGeometry3D();

            mesh3D.Positions       = new Point3DCollection(mesh.Vertices.Select(p => new Point3D(p.X, p.Y, p.Z)));
            mesh3D.TriangleIndices = new Int32Collection(mesh.Triangles.SelectMany(t => t.VertexIndizes));
            if (mesh.HasNormals)
            {
                mesh3D.Normals = new Vector3DCollection(mesh.Vertices.Select(v => new Vector3D(v.Normal.X, v.Normal.Y, v.Normal.Z)));
            }

            var meshVisual = new MeshGeometryVisual3D()
            {
                MeshGeometry = mesh3D,
                Material     = frontMaterial,
                BackMaterial = backMaterial
            };

            return(meshVisual);
        }
示例#6
0
        protected override Visual3D CreateVisual(SceneActor renderItem)
        {
            MeshGeometryVisual3D visual = new MeshGeometryVisual3D();

            visual.MeshGeometry = renderItem.Geometry;
            visual.Material     = new DiffuseMaterial(new SolidColorBrush(System.Windows.Media.Color.FromArgb(255, 122, 122, 122)));
            return(visual);
            ////Need to Vertexes to points3d
            //List<Point3D> vertexes = new List<Point3D>();
            //foreach(Vector3 v in model.Vertices)
            //{
            //    vertexes.Add(new Point3D(v.X, v.Y, v.Z));
            //}
            ////Collapse indices to one list
            //List<int> indices = new List<int>();
            //indices.AddRange(model.Faces);
            ////Create normals on wpf vector format
            //List<Vector3D> normals = new List<Vector3D>();
            //foreach(Vector3 vn in model.VertexNomals)
            //{
            //    normals.Add(new Vector3D(vn.X, vn.Y, vn.Z));
            //}

            //if(normals.Count == 0)
            //{
            //    meshBuilder.Append(vertexes, indices);
            //}
            //else
            //{
            //    meshBuilder.Append(vertexes, indices, normals);
            //}

            //return meshBuilder.ToMesh();
        }
示例#7
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Rectangle3DVisualizationObject"/> class.
        /// </summary>
        public Rectangle3DVisualizationObject()
        {
            // Create the fill mesh
            this.modelVisual = new MeshGeometryVisual3D
            {
                MeshGeometry = new MeshGeometry3D(),
            };

            this.modelVisual.MeshGeometry.Positions.Add(default);
示例#8
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Mesh3DVisualizationObject"/> class.
        /// </summary>
        public Mesh3DVisualizationObject()
        {
            this.modelVisual = new MeshGeometryVisual3D
            {
                MeshGeometry = new MeshGeometry3D(),
            };

            this.UpdateVisibility();
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="DepthImageRectangle3DVisualizationObject"/> class.
        /// </summary>
        public DepthImageRectangle3DVisualizationObject()
        {
            // Create a rectangle mesh for the image
            this.displayImage          = new DisplayImage();
            this.depthImageModelVisual = new MeshGeometryVisual3D
            {
                MeshGeometry = new MeshGeometry3D(),
            };

            this.depthImageModelVisual.MeshGeometry.Positions.Add(default);
示例#10
0
        private void OnCompleted()
        {
            bool ok;
            var  probing = DataContext as ProbingViewModel;

            if ((ok = probing.IsSuccess))
            {
                probing.GotoMachinePosition(probing.StartPosition, AxisFlags.Z);
                probing.GotoMachinePosition(probing.StartPosition, AxisFlags.X | AxisFlags.Y);

                if (probing.HeightMap.SetToolOffset)
                {
                    if (probing.CoordinateMode == ProbingViewModel.CoordMode.G10)
                    {
                        probing.Grbl.ExecuteCommand(string.Format("G10L2P{0}Z{1}", probing.CoordinateSystem, (probing.Positions[0].Z - probing.Grbl.ToolOffset.Z).ToInvariantString()));
                    }
                    else if ((ok == probing.GotoMachinePosition(probing.Positions[0], AxisFlags.Z)))
                    {
                        probing.Grbl.ExecuteCommand("G92Z0");
                        probing.GotoMachinePosition(probing.StartPosition, AxisFlags.Z);
                        if (!probing.Grbl.IsParserStateLive)
                        {
                            probing.Grbl.ExecuteCommand("$G");
                        }
                    }
                }

                double Z0 = probing.Positions[0].Z, z_min = 0d, z_max = 0d, z_delta;

                foreach (var pos in probing.Positions)
                {
                    z_delta = pos.Z - Z0;
                    z_min   = Math.Min(z_min, z_delta);
                    z_max   = Math.Max(z_max, z_delta);
                    probing.HeightMap.Map.AddPoint(toIndex(pos.X - probing.StartPosition.X), toIndex(pos.Y - probing.StartPosition.Y), Math.Round(z_delta, probing.Grbl.Precision));
                }

                LinesVisual3D        boundary = new LinesVisual3D();
                PointsVisual3D       mapPoints = new PointsVisual3D();
                MeshGeometryVisual3D mesh = new MeshGeometryVisual3D();

                // TODO: fix HeightMap object...
                probing.HeightMap.Map.GetModel(mesh);
                probing.HeightMap.Map.GetPreviewModel(boundary, mapPoints);

                probing.HeightMap.MeshGeometry   = mesh.MeshGeometry;
                probing.HeightMap.BoundaryPoints = boundary.Points;
                probing.HeightMap.MapPoints      = mapPoints.Points;
                probing.HeightMap.HasHeightMap   = true;

                probing.Program.End(ok ? string.Format("Probing completed: Z min: {0}, Z max: {1}", z_min.ToInvariantString(probing.Grbl.Format), z_max.ToInvariantString(probing.Grbl.Format)) : "Probing failed");
            }
        }
示例#11
0
        private void Probing_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
        {
            switch (e.PropertyName)
            {
            case nameof(ProbingViewModel.IsCompleted):

                bool ok      = true;
                var  probing = DataContext as ProbingViewModel;

                probing.PropertyChanged -= Probing_PropertyChanged;

                if (probing.IsSuccess)
                {
                    probing.GotoMachinePosition(origin, AxisFlags.Z);
                    probing.GotoMachinePosition(origin, AxisFlags.X | AxisFlags.Y);

                    if (probing.HeightMap.SetToolOffset)
                    {
                        if ((ok == probing.GotoMachinePosition(probing.Positions[0], AxisFlags.Z)))
                        {
                            probing.Grbl.ExecuteCommand("G92Z0");
                            probing.GotoMachinePosition(origin, AxisFlags.Z);
                        }
                    }

                    double Z0 = probing.Positions[0].Z;

                    foreach (var pos in probing.Positions)
                    {
                        probing.HeightMap.Map.AddPoint(toIndex(pos.X - origin.X), toIndex(pos.Y - origin.Y), Math.Round(pos.Z - Z0, probing.Grbl.Precision));
                    }

                    LinesVisual3D        boundary  = new LinesVisual3D();
                    PointsVisual3D       mapPoints = new PointsVisual3D();
                    MeshGeometryVisual3D mesh      = new MeshGeometryVisual3D();

                    // TODO: fix HeightMap object...
                    probing.HeightMap.Map.GetModel(mesh);
                    probing.HeightMap.Map.GetPreviewModel(boundary, mapPoints);

                    probing.HeightMap.MeshGeometry   = mesh.MeshGeometry;
                    probing.HeightMap.BoundaryPoints = boundary.Points;
                    probing.HeightMap.MapPoints      = mapPoints.Points;
                    probing.HeightMap.HasHeightMap   = true;

                    probing.Program.End(ok ? "Probing completed" : "Probing failed");
                }
                origin = null;
                break;
            }
        }
示例#12
0
        private void CreateFaceModels(IFCItem item, Vector3D center)
        {
            while (item != null)
            {
                if (item.ifcID != IntPtr.Zero && item.noVerticesForFaces != 0 && item.noPrimitivesForFaces != 0)
                {
                    var positions = new Point3DCollection();
                    var normals   = new Vector3DCollection();
                    if (item.verticesForFaces != null)
                    {
                        for (int i = 0; i < item.noVerticesForFaces; i++)
                        {
                            var point  = new Point3D(item.verticesForFaces[6 * i + 0] - center.X, item.verticesForFaces[6 * i + 1] - center.Y, item.verticesForFaces[6 * i + 2] - center.Z);
                            var normal = new Vector3D(item.verticesForFaces[6 * i + 3], item.verticesForFaces[6 * i + 4], item.verticesForFaces[6 * i + 5]);
                            positions.Add(point);
                            normals.Add(normal);
                        }

                        Debug.Assert(item.verticesForFaces.Length == item.noVerticesForFaces * 6);
                    }

                    var indices = new Int32Collection();
                    if (item.indicesForFaces != null)
                    {
                        for (int i = 0; i < 3 * item.noPrimitivesForFaces; i++)
                        {
                            indices.Add(item.indicesForFaces[i]);
                        }
                    }

                    MeshGeometry3D meshGeometry = new MeshGeometry3D();
                    meshGeometry.Positions       = positions;
                    meshGeometry.Normals         = normals;
                    meshGeometry.TriangleIndices = indices;
                    MeshGeometryVisual3D mesh = new MeshGeometryVisual3D();
                    mesh.MeshGeometry     = meshGeometry;
                    item.Mesh3d           = mesh;
                    _meshToIfcItems[mesh] = item;
#if DEBUG
                    OutputObj(item.ifcID.ToString(), meshGeometry);
#endif
                    FillMeshByIfcColor(item);

                    hVp3D.Children.Add(mesh);
                }

                CreateFaceModels(item.child, center);
                item = item.next;
            }
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="ImageCameraViewVisualizationObject"/> class.
        /// </summary>
        public ImageCameraViewVisualizationObject()
        {
            // Instantiate the child visualizer for visualizing the camera frustum,
            // and register for its property changed notifications.
            this.frustum = new CameraIntrinsicsWithPoseVisualizationObject();
            this.frustum.RegisterChildPropertyChangedNotifications(this, nameof(this.Frustum));

            // Create a rectangle mesh for the image
            this.displayImage     = new DisplayImage();
            this.imageModelVisual = new MeshGeometryVisual3D
            {
                MeshGeometry = new Win3D.MeshGeometry3D(),
            };

            this.imageModelVisual.MeshGeometry.Positions.Add(default);
示例#14
0
        private static async Task <MeshGeometryVisual3D> OpenModel(string fileName)
        {
            CurrentFile      = fileName;
            CurrentDirectory = Path.GetDirectoryName(CurrentFile);
            var cutFileName = CurrentFile.Remove(CurrentFile.Length - 5);
            var geometry    = await GeometryCreator.CreateGeometryAsync(cutFileName + "d.dat");

            var material = await MaterialCreator.CreateMaterialAsync(cutFileName + "c.bmp");

            Model = new MeshGeometryVisual3D()
            {
                MeshGeometry = (MeshGeometry3D)geometry,
                Material     = material
            };
            return(Model);
        }
        private void OnCompleted()
        {
            bool ok;
            var  probing = DataContext as ProbingViewModel;

            if ((ok = probing.IsSuccess))
            {
                probing.GotoMachinePosition(origin, AxisFlags.Z);
                probing.GotoMachinePosition(origin, AxisFlags.X | AxisFlags.Y);

                if (probing.HeightMap.SetToolOffset)
                {
                    if (probing.CoordinateMode == ProbingViewModel.CoordMode.G10)
                    {
                        probing.Grbl.ExecuteCommand(string.Format("G10L2P{0}Z{1}", probing.CoordinateSystem, (probing.Positions[0].Z - probing.Grbl.ToolOffset.Z).ToInvariantString()));
                    }
                    else if ((ok == probing.GotoMachinePosition(probing.Positions[0], AxisFlags.Z)))
                    {
                        probing.Grbl.ExecuteCommand("G92Z0");
                        probing.GotoMachinePosition(origin, AxisFlags.Z);
                    }
                }

                double Z0 = probing.Positions[0].Z;

                foreach (var pos in probing.Positions)
                {
                    probing.HeightMap.Map.AddPoint(toIndex(pos.X - origin.X), toIndex(pos.Y - origin.Y), Math.Round(pos.Z - Z0, probing.Grbl.Precision));
                }

                LinesVisual3D        boundary  = new LinesVisual3D();
                PointsVisual3D       mapPoints = new PointsVisual3D();
                MeshGeometryVisual3D mesh      = new MeshGeometryVisual3D();

                // TODO: fix HeightMap object...
                probing.HeightMap.Map.GetModel(mesh);
                probing.HeightMap.Map.GetPreviewModel(boundary, mapPoints);

                probing.HeightMap.MeshGeometry   = mesh.MeshGeometry;
                probing.HeightMap.BoundaryPoints = boundary.Points;
                probing.HeightMap.MapPoints      = mapPoints.Points;
                probing.HeightMap.HasHeightMap   = true;

                probing.Program.End(ok ? "Probing completed" : "Probing failed");
            }
            origin = null;
        }
示例#16
0
        private void OnCompleted()
        {
            bool ok;
            var  probing = DataContext as ProbingViewModel;

            if ((ok = probing.IsSuccess && probing.Positions.Count == probing.HeightMap.Map.TotalPoints))
            {
                probing.GotoMachinePosition(probing.StartPosition, AxisFlags.Z);
                probing.GotoMachinePosition(probing.StartPosition, AxisFlags.X | AxisFlags.Y);

                if (probing.HeightMap.SetToolOffset)
                {
                    if (probing.CoordinateMode == ProbingViewModel.CoordMode.G10)
                    {
                        probing.Grbl.ExecuteCommand(string.Format("G10L2P{0}Z{1}", probing.CoordinateSystem, (probing.Positions[0].Z - probing.Grbl.ToolOffset.Z).ToInvariantString()));
                    }
                    else if ((ok == probing.GotoMachinePosition(probing.Positions[0], AxisFlags.Z)))
                    {
                        probing.Grbl.ExecuteCommand("G92Z0");
                        probing.GotoMachinePosition(probing.StartPosition, AxisFlags.Z);
                        if (!probing.Grbl.IsParserStateLive)
                        {
                            probing.Grbl.ExecuteCommand("$G");
                        }
                    }
                }

                double Z0 = probing.Positions[0].Z, z_min = 0d, z_max = 0d, z_delta;

                int i = 0;
                for (x = 0; x < probing.HeightMap.Map.SizeX; x++)
                {
                    for (y = 0; y < probing.HeightMap.Map.SizeY; y++)
                    {
                        z_delta = probing.Positions[i++].Z - Z0;
                        z_min   = Math.Min(z_min, z_delta);
                        z_max   = Math.Max(z_max, z_delta);
                        probing.HeightMap.Map.AddPoint(x, y, Math.Round(z_delta, probing.Grbl.Precision));
                    }
                    if (++x < probing.HeightMap.Map.SizeX)
                    {
                        for (y = probing.HeightMap.Map.SizeY - 1; y >= 0; y--)
                        {
                            z_delta = probing.Positions[i++].Z - Z0;
                            z_min   = Math.Min(z_min, z_delta);
                            z_max   = Math.Max(z_max, z_delta);
                            probing.HeightMap.Map.AddPoint(x, y, Math.Round(z_delta, probing.Grbl.Precision));
                        }
                    }
                }

                LinesVisual3D        boundary  = new LinesVisual3D();
                PointsVisual3D       mapPoints = new PointsVisual3D();
                MeshGeometryVisual3D mesh      = new MeshGeometryVisual3D();

                // TODO: fix HeightMap object...
                probing.HeightMap.Map.GetModel(mesh);
                probing.HeightMap.Map.GetPreviewModel(boundary, mapPoints);

                probing.HeightMap.MeshGeometry   = mesh.MeshGeometry;
                probing.HeightMap.BoundaryPoints = boundary.Points;
                probing.HeightMap.MapPoints      = mapPoints.Points;
                probing.HeightMap.HasHeightMap   = true;

                probing.Program.End(ok ? string.Format((string)FindResource("ProbingCompleted"), z_min.ToInvariantString(probing.Grbl.Format), z_max.ToInvariantString(probing.Grbl.Format)) : (string)FindResource("ProbingFailed"));
            }
        }