Esempio n. 1
0
        private EMFace MergeFaces(EMFace A, EMFace B)
        {
            if (Object.ReferenceEquals(A, B))
            {
                throw new InvalidOperationException("Attempt to merge face with itself");
            }

            EMEdge sharedEdge = null;

            foreach (var e in A.edges)
            {
                if (e.Neighbors.Contains(B))
                {
                    sharedEdge = e;
                }
            }
            if (sharedEdge == null)
            {
                throw new InvalidOperationException("Attempt to merge faces with no shared edge.");
            }

            var newFace = new EMFace();

            newFace.edges = new List <EMEdge>(A.edges);
            newFace.edges.InsertRange(0, B.edges);
            newFace.edges.RemoveAll((e) => Object.ReferenceEquals(e, sharedEdge));

            if (newFace.edges.Count <= 2)
            {
                throw new InvalidOperationException("Degenerate face generated");
            }

            return(newFace);
        }
Esempio n. 2
0
        private short[] ExtractPointSequence(EMEdge a, EMEdge b)
        {
            var points = new short[3];

            if (b.Verticies.Contains(a.Verticies[1]))
            {
                points[0] = a.Verticies[0];
                points[1] = a.Verticies[1];
            }
            else
            {
                points[0] = a.Verticies[1];
                points[1] = a.Verticies[0];
            }

            if (b.Verticies[0] == points[1])
            {
                points[2] = b.Verticies[1];
            }
            else
            {
                points[2] = b.Verticies[0];
            }

            return(points);
        }
Esempio n. 3
0
        public bool EdgesAreColinear(EMEdge A, EMEdge B)
        {
            var points = new List<Vector3>(ExtractPointSequence(A, B).Select((s) => Verticies[s]));
            var v0 = points[1] - points[0];
            var v1 = points[2] - points[1];

            return Gem.Math.Utility.AlmostZero(AngleBetweenVectors(v0, v1));
        }
Esempio n. 4
0
        public bool EdgesAreColinear(EMEdge A, EMEdge B)
        {
            var points = new List <Vector3>(ExtractPointSequence(A, B).Select((s) => Verticies[s]));
            var v0     = points[1] - points[0];
            var v1     = points[2] - points[1];

            return(Gem.Math.Utility.AlmostZero(AngleBetweenVectors(v0, v1)));
        }
Esempio n. 5
0
 private EMFace OtherNeighbor(EMEdge e, EMFace f)
 {
     if (Object.ReferenceEquals(e.Neighbors[0], f))
     {
         return(e.Neighbors[1]);
     }
     else
     {
         return(e.Neighbors[0]);
     }
 }
Esempio n. 6
0
 internal void SetRecipricalNeighbor(EMEdge edge, EMFace neighbor)
 {
     foreach (var e in edges)
     {
         if (Object.ReferenceEquals(e, edge))
         {
             e.Neighbors[1] = neighbor;
         }
     }
     //for (int i = 0; i < 3; ++i)
     //    if (Object.ReferenceEquals(Edges[i],edge)) Neighbors[i] = neighbor;
 }
Esempio n. 7
0
 private EMEdge FindNextEdgeInSequence(EMFace of, EMEdge after, short endpoint)
 {
     foreach (var e in of.edges)
     {
         if (Object.ReferenceEquals(e, after))
         {
             continue;
         }
         if (e.Verticies.Contains(endpoint))
         {
             return(e);
         }
     }
     throw new InvalidOperationException("Malformed edge mesh");
 }
Esempio n. 8
0
 private short FindSharedEndpoint(EMEdge a, EMEdge b)
 {
     if (b.Verticies.Contains(a.Verticies[0]))
     {
         return(a.Verticies[0]);
     }
     else if (b.Verticies.Contains(a.Verticies[1]))
     {
         return(a.Verticies[1]);
     }
     else
     {
         throw new InvalidOperationException("Attempt to find shared endpoint of edges with no shared endpoint");
     }
 }
Esempio n. 9
0
        private short[] ExtractPointSequence(EMEdge a, EMEdge b)
        {
            var points = new short[3];

            if (b.Verticies.Contains(a.Verticies[1]))
            {
                points[0] = a.Verticies[0];
                points[1] = a.Verticies[1];
            }
            else
            {
                points[0] = a.Verticies[1];
                points[1] = a.Verticies[0];
            }

            if (b.Verticies[0] == points[1])
                points[2] = b.Verticies[1];
            else
                points[2] = b.Verticies[0];

            return points;
        }
Esempio n. 10
0
 private EMFace OtherNeighbor(EMEdge e, EMFace f)
 {
     if (Object.ReferenceEquals(e.Neighbors[0], f)) return e.Neighbors[1];
     else return e.Neighbors[0];
 }
Esempio n. 11
0
 private short FindSharedEndpoint(EMEdge a, EMEdge b)
 {
     if (b.Verticies.Contains(a.Verticies[0])) return a.Verticies[0];
     else if (b.Verticies.Contains(a.Verticies[1])) return a.Verticies[1];
     else throw new InvalidOperationException("Attempt to find shared endpoint of edges with no shared endpoint");
 }
Esempio n. 12
0
 private EMEdge FindNextEdgeInSequence(EMFace of, EMEdge after, short endpoint)
 {
     foreach (var e in of.edges)
     {
         if (Object.ReferenceEquals(e, after)) continue;
         if (e.Verticies.Contains(endpoint)) return e;
     }
     throw new InvalidOperationException("Malformed edge mesh");
 }
Esempio n. 13
0
 public Vector3 FindEdgeCenter(EMEdge e)
 {
     return (Verticies[e.Verticies[0]] + Verticies[e.Verticies[1]]) / 2.0f;
 }
Esempio n. 14
0
 internal void SetRecipricalNeighbor(EMEdge edge, EMFace neighbor)
 {
     foreach (var e in edges)
         if (Object.ReferenceEquals(e, edge)) e.Neighbors[1] = neighbor;
     //for (int i = 0; i < 3; ++i)
     //    if (Object.ReferenceEquals(Edges[i],edge)) Neighbors[i] = neighbor;
 }
Esempio n. 15
0
 public Vector3 FindEdgeCenter(EMEdge e)
 {
     return((Verticies[e.Verticies[0]] + Verticies[e.Verticies[1]]) / 2.0f);
 }