コード例 #1
0
 private HalfEdgeMesh CreateUnitCubeMesh()
 {
     var vertices = new[]
         {
             new Point3D(0, 0, 0), new Point3D(1, 0, 0), new Point3D(1, 1, 0), new Point3D(0, 1, 0),
             new Point3D(0, 0, 1), new Point3D(1, 0, 1), new Point3D(1, 1, 1), new Point3D(0, 1, 1)
         };
     var mesh = new HalfEdgeMesh(vertices);
     mesh.AddFace(3, 2, 1, 0);
     mesh.AddFace(4, 5, 6, 7);
     mesh.AddFace(0, 1, 5, 4);
     mesh.AddFace(1, 2, 6, 5);
     mesh.AddFace(2, 3, 7, 6);
     mesh.AddFace(3, 0, 4, 7);
     return mesh;
 }
コード例 #2
0
 public MainWindow()
 {
     InitializeComponent();
     DataContext = this;
     this.Mesh = CreateUnitCubeMesh();
 }
コード例 #3
0
        /// <summary>
        /// The highlight face.
        /// </summary>
        /// <param name="face">
        /// The face.
        /// </param>
        private void HighlightFace(HalfEdgeMesh.Face face)
        {
            var adjacentFaces = new HashSet<HalfEdgeMesh.Face>(face.AdjacentFaces);
            var adjacentVertices = new HashSet<HalfEdgeMesh.Vertex>(face.Vertices);
            var edges = new HashSet<HalfEdgeMesh.HalfEdge>(face.Edges);
            foreach (var f in this.Mesh.Faces)
            {
                var element = this.faceVisuals[f];
                var model = element.Model as GeometryModel3D;
                if (f == face)
                {
                    model.Material = this.SelectedMaterial;
                }
                else if (adjacentFaces.Contains(f))
                {
                    model.Material = this.AdjacentMaterial;
                }
                else
                {
                    model.Material = this.UnselectedMaterial;
                }
            }

            foreach (var v in this.Mesh.Vertices)
            {
                var element = this.vertexVisuals[v];
                var model = element.Model as GeometryModel3D;
                if (adjacentVertices.Contains(v))
                {
                    model.Material = this.AdjacentMaterial;
                }
                else
                {
                    model.Material = this.UnselectedMaterial;
                }
            }

            foreach (var e in this.Mesh.Edges)
            {
                var element = this.halfEdgeVisuals[e];
                var model = element.Model as GeometryModel3D;
                if (edges.Contains(e))
                {
                    model.Material = this.ConnectedMaterial;
                }
                else
                {
                    model.Material = this.UnselectedMaterial;
                }
            }
        }
コード例 #4
0
        /// <summary>
        /// The highlight vertex.
        /// </summary>
        /// <param name="vertex">
        /// The vertex.
        /// </param>
        private void HighlightVertex(HalfEdgeMesh.Vertex vertex)
        {
            var adjacentFaces = new HashSet<HalfEdgeMesh.Face>(vertex.AdjacentFaces);
            var adjacentVertices = new HashSet<HalfEdgeMesh.Vertex>(vertex.Vertices);
            var incomingEdges = new HashSet<HalfEdgeMesh.HalfEdge>(vertex.IncomingEdges);
            var outgoingEdges = new HashSet<HalfEdgeMesh.HalfEdge>(vertex.OutgoingEdges);

            foreach (var f in this.Mesh.Faces)
            {
                var element = this.faceVisuals[f];
                var model = element.Model as GeometryModel3D;
                if (adjacentFaces.Contains(f))
                {
                    model.Material = this.AdjacentMaterial;
                }
                else
                {
                    model.Material = this.UnselectedMaterial;
                }
            }

            foreach (var v in this.Mesh.Vertices)
            {
                var element = this.vertexVisuals[v];
                var model = element.Model as GeometryModel3D;
                if (v == vertex)
                {
                    model.Material = this.SelectedMaterial;
                }
                else if (adjacentVertices.Contains(v))
                {
                    model.Material = this.AdjacentMaterial;
                }
                else
                {
                    model.Material = this.UnselectedMaterial;
                }
            }

            foreach (var e in this.Mesh.Edges)
            {
                var element = this.halfEdgeVisuals[e];
                var model = element.Model as GeometryModel3D;
                if (incomingEdges.Contains(e))
                {
                    model.Material = this.AdjacentMaterial;
                }
                else if (outgoingEdges.Contains(e))
                {
                    model.Material = this.ConnectedMaterial;
                }
                else
                {
                    model.Material = this.UnselectedMaterial;
                }
            }
        }
コード例 #5
0
        /// <summary>
        /// The highlight edge.
        /// </summary>
        /// <param name="edge">
        /// The edge.
        /// </param>
        private void HighlightEdge(HalfEdgeMesh.HalfEdge edge)
        {
            foreach (var f in this.Mesh.Faces)
            {
                var element = this.faceVisuals[f];
                var model = element.Model as GeometryModel3D;
                if (edge.Face == f)
                {
                    model.Material = this.ConnectedMaterial;
                }
                else if (edge.AdjacentFace == f)
                {
                    model.Material = this.AdjacentMaterial;
                }
                else
                {
                    model.Material = this.UnselectedMaterial;
                }
            }

            foreach (var v in this.Mesh.Vertices)
            {
                var element = this.vertexVisuals[v];
                var model = element.Model as GeometryModel3D;
                if (v == edge.StartVertex)
                {
                    model.Material = Materials.Black;
                }
                else if (v == edge.EndVertex)
                {
                    model.Material = Materials.White;
                }
                else
                {
                    model.Material = this.UnselectedMaterial;
                }
            }

            foreach (var e in this.Mesh.Edges)
            {
                var element = this.halfEdgeVisuals[e];
                var model = element.Model as GeometryModel3D;
                if (e == edge)
                {
                    model.Material = this.SelectedMaterial;
                }
                else if (e == edge.AdjacentEdge)
                {
                    model.Material = this.AdjacentMaterial;
                }
                else
                {
                    model.Material = this.UnselectedMaterial;
                }
            }
        }