Exemple #1
0
 public DCELHalfEdge(DCELVertex origin, DCELFace face, DCELHalfEdge twin, DCELHalfEdge next)
 {
     Origin = origin;
     Face   = face;
     Twin   = twin;
     Next   = next;
 }
Exemple #2
0
        public bool AddFace(DCELFace face)
        {
            faceList.Add(face);
            faceCount++;

            return(true);
        }
Exemple #3
0
 public bool RemoveFace(DCELFace face)
 {
     if (faceList.Remove(face))
     {
         faceCount--;
         return(true);
     }
     return(false);
 }
Exemple #4
0
        public bool TriangulateFace(DCELFace face)
        {
            //lista di appoggio
            List <DCELHalfEdge> edges = face.Sides().ToList();
            //sides è il numero di lati della faccia
            int sides = edges.Count;
            //first è il vertice a partire dal quale viene suddiviso il poligono
            DCELVertex first = edges[0].Origin;

            //se la faccia non esiste o se esiste ma ha meno di 4 lati o non è convessa restituisco false
            //if (sides <= 3 || !this.Contains(face) || !face.IsConvex())
            //    return false;

            for (int i = 0; i < sides; i++)
            {
                if (i == 0)
                {
                    this.AddFace(new DCELFace(edges[i], face.Normal));
                    edges[i].Face = faceList[FaceCount - 1];
                    i++;
                    edges[i].Face = faceList[FaceCount - 1];
                    this.AddHalfEdge(new DCELHalfEdge(edges[i].Next.Origin, faceList[FaceCount - 1], null, edges[0]));
                    edges[i].Next = edgeList[HalfEdgeCount - 1];
                }
                else if (i == sides - 2)
                {
                    this.AddFace(new DCELFace(null, face.Normal));
                    this.AddHalfEdge(new DCELHalfEdge(first, faceList[FaceCount - 1], edgeList[HalfEdgeCount - 1], edges[i]));
                    edges[i].Face = faceList[FaceCount - 1];
                    i++;
                    edges[i].Face = faceList[FaceCount - 1];
                    edgeList[HalfEdgeCount - 2].Twin = edgeList[HalfEdgeCount - 1];
                    faceList[FaceCount - 1].Edge     = edgeList[HalfEdgeCount - 1];
                    edges[i].Next = edgeList[HalfEdgeCount - 1];
                }
                else
                {
                    this.AddFace(new DCELFace(null, face.Normal));
                    this.AddHalfEdge(new DCELHalfEdge(first, faceList[FaceCount - 1], edgeList[HalfEdgeCount - 1], edges[i]));
                    faceList[FaceCount - 1].Edge = edgeList[HalfEdgeCount - 1];
                    edges[i].Face = faceList[FaceCount - 1];
                    edgeList[HalfEdgeCount - 2].Twin = edgeList[HalfEdgeCount - 1];
                    this.AddHalfEdge(new DCELHalfEdge(edges[i].Next.Origin, faceList[faceCount - 1], null, edgeList[HalfEdgeCount - 1]));
                    edges[i].Next = edgeList[HalfEdgeCount - 1];
                }
            }
            //ora è possibile rimuovere la faccia dalla lista
            return(RemoveFace(face));
        }
Exemple #5
0
        public static void CalculateNormal(DCELFace dcelFace)
        {
            Vector3D vector1 = new Vector3D(
                dcelFace.Edge.Next.Origin.Coordinates.X - dcelFace.Edge.Origin.Coordinates.X,
                dcelFace.Edge.Next.Origin.Coordinates.Y - dcelFace.Edge.Origin.Coordinates.Y,
                dcelFace.Edge.Next.Origin.Coordinates.Z - dcelFace.Edge.Origin.Coordinates.Z);

            Vector3D vector2 = new Vector3D(
                dcelFace.Edge.Next.Next.Origin.Coordinates.X - dcelFace.Edge.Origin.Coordinates.X,
                dcelFace.Edge.Next.Next.Origin.Coordinates.Y - dcelFace.Edge.Origin.Coordinates.Y,
                dcelFace.Edge.Next.Next.Origin.Coordinates.Z - dcelFace.Edge.Origin.Coordinates.Z);

            //normale
            Vector3D normal = CrossProduct(vector1, vector2);

            dcelFace.Normal = Normalize(normal);
        }
Exemple #6
0
 public bool Contains(DCELFace face)
 {
     return(faceList.Contains(face));
 }