示例#1
0
        /// <summary>
        /// gets the dual <see cref="Edge"/> of the <see cref="Face"/>. The Edge is <see cref="Face.Bounds"/>[inLoop][id].
        /// </summary>
        /// <param name="Face">Face from the edge.</param>
        /// <param name="inLoop">Index in <see cref="Face.Bounds"/>.</param>
        /// <param name="id">Index in <see cref="Face.Bounds"/>[inLoop]</param>
        /// <returns>the dual <see cref="Edge"/>.</returns>
        public static Edge GetDualEdge(Face Face, int inLoop, int id)
        {
            Edge     E        = Face.Bounds[inLoop][id];
            Vertex3d A        = E.EdgeStart;
            Vertex3d B        = E.EdgeEnd;
            Face     Neighbor = Face.Neighbor(inLoop, id) as Face;

            if (Neighbor == null)
            {
                return(null);
            }
            int OutLoop = -1;

            for (int i1 = 0; i1 < Neighbor.Bounds.Count; i1++)
            {
                OutLoop = i1;

                for (int i = 0; i < Neighbor.Bounds[i1].Count; i++)
                {
                    if (((Neighbor.Bounds[i1][i].EdgeStart.Value.dist(B.Value) < 0.00001) &&
                         (Neighbor.Bounds[i1][i].EdgeEnd.Value.dist(A.Value) < 0.00001)) ||
                        ((Neighbor.Bounds[i1][i].EdgeStart.Value.dist(A.Value) < 0.00001)) &&
                        (Neighbor.Bounds[i1][i].EdgeEnd.Value.dist(B.Value) < 0.00001))
                    {
                        return(Neighbor.Bounds[i1][i]);
                    }
                }
            }
            return(null);
        }
示例#2
0
        /// <summary>
        /// creates a <see cref="Face"/> for a <see cref="Solid"/> with <see cref="Model.Solid"/>.
        /// <b>Curves</b>
        ///
        ///
        ///
        ///
        /// Erstell ein massives <see cref="Face"/>. Wenn <b>Solid</b> nicht null ist, wird dieses Face eingebaut in
        /// <b>Solid</b>. <b>Curves</b> spezifizieren einee Liste von Curve3d-Lists. Sie werden als <see cref="Edge.EdgeCurve"/>
        /// in jede <see cref="Edge"/> gesetzt. <b>Curves</b> müssen von der Struktur identisch sein wie Bounds,
        /// d.h. die selbe Länge und jeder Eintrag in Bounds ( Bounds[i] ) muss die selbe Länge haben wie
        /// der entsprechende Eintrag in <b>Curves</b> (Curves[i]).
        /// gesetzt
        /// </summary>
        /// <param name="Solid"><see cref="Solid"/> in which the result<see cref="Face"/> will be integrated.</param>
        /// <param name="Surface"><see cref="Surface"/> belonging to the new <see cref="Face"/>.</param>
        /// <param name="Bounds">list of <see cref="Vertex3dArray"/>, who contains the start and end points of the <see cref="Edge"/>s.</param>
        /// <param name="Curves"><see cref="Curve3D"/>, which are the new <see cref="Edge.EdgeCurve"/>s. Their start points and their end point must correspond to
        /// the parameter Bounds start and end points.</param>
        /// <returns>a <see cref="Face"/>, which will be added to the <b>Solid</b>.</returns>
        public static Face SolidFace(Solid Solid, Surface Surface, Vertex3dArray_2 Bounds, Loca3D Curves)
        {
            if (Bounds.Count == 0)
            {
                return(null);
            }

            Face Result = new Face();

            Result.Surface = Surface;
            for (int i = 0; i < Bounds.Count; i++)
            {
                EdgeLoop Edgeloop = new EdgeLoop();
                Result.Bounds.Add(Edgeloop);
                for (int j = 0; j < Bounds[i].Count; j++)
                {
                    Vertex3d A = Bounds[i][j];
                    Vertex3d B = null;
                    if (j == Bounds[i].Count - 1)
                    {
                        B = Bounds[i][0];
                    }
                    else
                    {
                        B = Bounds[i][j + 1];
                    }

                    Edge E = Edge.SolidEdge(Solid, Result, A, B, Curves[j][i]);

                    Edgeloop.Add(E);
                }
            }
            return(Result);
        }
示例#3
0
        /// <summary>
        /// generates an edge in <see cref="Drawing3d.Model.Solid"/> model. The belonging <b>Face</b>,
        /// the start point, the end point and with the difference to <see cref="SolidEdge(Solid,Face, Vertex3d, Vertex3d,Curve3D)"/>
        /// the the paramcurve on the <b>Face</b> must be specified.
        /// </summary>
        /// <param name="Solid"><see cref="Solid"/>, in which the <see cref="Edge"/> should be generated.</param>
        /// <param name="Face">the <see cref="Face"/> for the <see cref="Edge"/>.</param>
        /// <param name="A">start point</param>
        /// <param name="B">end point</param>
        /// <param name="ParamCurve">paramcurve on the <b>Face</b></param>
        /// <returns>a <b>edge</b>in the <see cref="Drawing3d.Model.Solid"/> model.</returns>
        public static Edge SolidEdge(Solid Solid, Face Face, Vertex3d A, Vertex3d B, Curve ParamCurve)
        {
            Curve3D Curve3d = GetEdgeCurve(Solid, B, A);

            Edge Result = new Edge();

            if (Curve3d == null)
            {
                Result.SameSense  = true;
                Curve3d           = Face.Surface.To3dCurve(ParamCurve);
                Result.ParamCurve = ParamCurve;
                Result.EdgeStart  = A;
                Result.EdgeEnd    = B;
            }
            else
            {
                Result.EdgeStart = B;
                Result.EdgeEnd   = A;
                ParamCurve.Invert();
                Result.ParamCurve = ParamCurve;
                Result.SameSense  = false;
            }
            Result.EdgeCurve = Curve3d; // muss vor Edges.add stehen weil es dort in die sufacelist aufgenommen wird
            Solid.EdgeList.Add(Result);
            return(Result);
        }
示例#4
0
        private void insertVertexToSameSenseEdge(Face Fa, int Bounds, int Edge, Vertex3d V)
        {
            EdgeLoop EL        = Fa.Bounds[Bounds];
            Edge     E         = EL[Edge];
            Face     Neigbhbor = null;
            int      outloop   = -1;
            double   d         = Face.GetDualEdge(Fa, Bounds, Edge + 0.5, ref outloop, ref Neigbhbor);
            EdgeLoop DualEL    = Neigbhbor.Bounds[outloop];

            int  DualEdge = (int)d;
            Edge F        = DualEL[DualEdge];
            // Zuerst die neue Kante

            Edge NewEdge = new Edge();

            EdgeList.Add(NewEdge);
            NewEdge.SameSense = true;
            NewEdge.EdgeStart = E.EdgeStart;
            NewEdge.EdgeEnd   = V;
            Line3D L = new Line3D(NewEdge.EdgeStart.Value, V.Value);

            EdgeCurveList.Add(L);
            L.Neighbors       = new Face[2];
            L.Neighbors[0]    = E.EdgeCurve.Neighbors[0];
            L.Neighbors[1]    = E.EdgeCurve.Neighbors[1];
            NewEdge.EdgeCurve = L;

            VertexList.Add(V);

            E.EdgeStart   = V;
            E.EdgeCurve.A = V.Value;

            EL.Insert(Edge, NewEdge);



            // Duale



            NewEdge           = new Edge();
            NewEdge.SameSense = false;
            EdgeList.Add(NewEdge);
            if (DualEdge + 1 < DualEL.Count)
            {
                DualEL.Insert(DualEdge + 1, NewEdge);
            }
            else
            {
                DualEL.Insert(0, NewEdge);
            }
            NewEdge.EdgeStart = V;
            NewEdge.EdgeEnd   = F.EdgeEnd;
            F.EdgeEnd         = V;
            NewEdge.EdgeCurve = L;
        }
示例#5
0
        static Curve3D GetEdgeCurve(Solid Solid, Vertex3d A, Vertex3d B)
        {
            Edge E = Solid.GetSurfaceEdge(A, B);

            if (E != null)
            {
                return(E.EdgeCurve);
            }
            return(null);
        }
示例#6
0
        /// <summary>
        /// copy the the edge <b>TargetSolid</b> and adds the copy to the EdgeList of the targetSolid .
        /// </summary>
        /// <param name="TargetSolid">solid, in which a copied edge should be created.</param>
        /// <returns>copy of the edge.</returns>
        public virtual Edge Copy(Solid TargetSolid)
        {
            Edge     Result = Activator.CreateInstance(this.GetType()) as Edge;
            Vertex3d VStart = null;
            Vertex3d VEnd   = null;

            {
                VStart        = new Vertex3d(EdgeStart.Value);
                EdgeStart.Tag = VStart;
                if (TargetSolid != null)
                {
                    TargetSolid.VertexList.Add(VStart);
                }
            }
            {
                VEnd        = new Vertex3d(EdgeEnd.Value);
                EdgeEnd.Tag = VEnd;
                if (TargetSolid != null)
                {
                    TargetSolid.VertexList.Add(VEnd);
                }
            }

            Result.EdgeStart = VStart;
            Result.EdgeEnd   = VEnd;

            Curve3D ECurve = null;

            if (TargetSolid != null)
            {
                ECurve = GetEdgeCurve(TargetSolid, VStart, VEnd);
                if (ECurve == null)
                {
                    ECurve = GetEdgeCurve(TargetSolid, VEnd, VStart);
                }
            }
            if (ECurve == null)
            {
                ECurve = EdgeCurve.Copy();
                if (TargetSolid != null)
                {
                    TargetSolid.EdgeCurveList.Add(ECurve);
                }
            }
            Result.EdgeCurve  = ECurve;
            Result.ParamCurve = ParamCurve.Clone();
            Result.CurveId    = CurveId;
            Result.SameSense  = SameSense;
            if (TargetSolid != null)
            {
                TargetSolid.EdgeList.Add(Result);
            }
            return(Result);
        }
示例#7
0
 /// <summary>
 /// gets an <see cref="Edge"/> belonging to the <see cref="Vertex3d"/> A and B.
 /// </summary>
 /// <param name="A">start point</param>
 /// <param name="B">end point</param>
 /// <returns>the <see cref="Edge"/> if it exists, else null.</returns>
 public Edge GetSurfaceEdge(Vertex3d A, Vertex3d B)
 {
     for (int i = 0; i < EdgeList.Count; i++)
     {
         Edge E = EdgeList[i];
         if ((E.EdgeStart == A) && (E.EdgeEnd == B))
         {
             return(E);
         }
     }
     return(null);
 }
示例#8
0
        /// <summary>
        /// gets the dual <see cref="Edge"/> in a <see cref="Face"/> which is given by <see cref="Face.Bounds"/>[Bound][(int)Param] In <b>OutBound</b> is the index of the dual <see cref="Edge"/> relativ to <b>Neighbor.Bounds</b>
        /// and the result value gives the parameter for the <see cref="Edge.ParamCurve"/> of this <see cref="Edge"/>. <b>Neighbor</b> is the neighbor <see cref="Face"/>.
        /// If no dual edge is found -1 will be returned.
        /// </summary>
        /// <param name="Face"><see cref="Face"/> in which <b>Bound</b> and <b>Param</b> are taken.</param>
        /// <param name="Bound">gives together with <b>Param</b> the <see cref="Edge"/> by <see cref="Face.Bounds"/>[Bound][(int)Param].</param>
        /// <param name="Param">gives together with <b>Bound</b> the <see cref="Edge"/> by <see cref="Face.Bounds"/>[Bound][(int)Param].</param>
        /// <param name="OutBound">is the bound index of the dual edge.</param>
        /// <param name="Neighbor">is the neighbor of <b>Face</b>.</param>
        /// <returns>a parameter, which gives togethe with <b>Outbound</b> the same point in the <b>dualedge</b> with dualedge.Paramcurve.value(parameter-(int)parameter.</returns>
        public static double GetDualEdge(Face Face, int Bound, double Param, ref int OutBound, ref Face Neighbor)
        {
            Edge E = Face.Bounds[Bound][(int)Param];

            Vertex3d A = E.EdgeStart;
            Vertex3d B = E.EdgeEnd;

            Neighbor = Face.Neighbor(Bound, (int)Param) as Face;
            if (Neighbor == null)
            {
                return(-1);
            }
            OutBound = -1;
            for (int i1 = 0; i1 < Neighbor.Bounds.Count; i1++)
            {
                OutBound = i1;

                for (int i = 0; i < Neighbor.Bounds[i1].Count; i++)
                {
                    if ((Neighbor.Bounds[i1][i].EdgeStart == B) &&
                        (Neighbor.Bounds[i1][i].EdgeEnd == A))
                    {
                        if (Param != (int)Param)
                        {
                            return(i + (1 - (Param - (int)Param)));
                        }

                        return(i);
                    }
                    if ((Neighbor.Bounds[i1][i].EdgeStart == A) &&
                        (Neighbor.Bounds[i1][i].EdgeEnd == B))
                    {
                        if (Param != (int)Param)
                        {
                            return(i + (1 - (Param - (int)Param)));
                        }
                        return(i);
                    }
                }
            }

            return(-1);
        }
示例#9
0
        /// <summary>
        /// generates in <see cref="Curve3D"/> in the <see cref="Drawing3d.Model.Solid"/> model an edge.
        /// It needs the belonging <b>Face</b>, the start point, the end point and the 3D-curve.
        /// </summary>
        /// <param name="Solid">solid, in which the edge should be generated.</param>
        /// <param name="Face"><see cref="Face"/>, in which the edge should be generated.</param>
        /// <param name="A">start point.</param>
        /// <param name="B">end point.</param>
        /// <param name="Curve">a 3D curve</param>
        /// <returns>an edge in the <see cref="Drawing3d.Model.Solid"/> model.</returns>
        public static Edge SolidEdge(Solid Solid, Face Face, Vertex3d A, Vertex3d B, Curve3D Curve)
        {
            bool    Orientation = true;
            Curve3D SC          = GetEdgeCurve(Solid, A, B);

            if (SC == null)
            {
                SC = GetEdgeCurve(Solid, B, A);
                if (SC != null)
                {
                    Orientation     = false;
                    SC.Neighbors[1] = Face;
                }
            }


            if (SC == null)
            {
                Curve.Neighbors    = new Face[2];
                Curve.Neighbors[0] = Face;
                if (Solid != null)
                {
                    Solid.EdgeCurveList.Add(Curve);
                }
                SC = Curve;
            }

            Edge Result = new Edge();

            Result.EdgeCurve = SC;
            Result.EdgeStart = A;
            Result.EdgeEnd   = B;
            Result.SameSense = Orientation;
            if (Solid != null)
            {
                Solid.EdgeList.Add(Result);
            }


            Result.ParamCurve = Face.Surface.To2dCurve(Curve);
            return(Result);
        }
示例#10
0
        /// <summary>
        /// Eine statische methode die einen Quader erstellt mit Ursprung <b>Origin</b> und
        /// Größe <b>Size</b>
        /// </summary>
        /// <param name="Origin">Ursprung des Quaders (rechts unten)</param>
        /// <param name="Size">Größe des Quaders</param>
        /// <returns>Ein solider Quader (Model.SolidSurface) </returns>
        public static Solid CreateSolidBox(xyz Origin, xyz Size)
        {
            Solid Box = new Solid();

            Box.Model = Model.Solid;
            Vertex3d A = new Vertex3d(Origin);
            Vertex3d B = new Vertex3d(Origin + new xyz(Size.x, 0, 0));

            Vertex3d C = new Vertex3d(Origin + new xyz(Size.x, Size.y, 0));
            Vertex3d D = new Vertex3d(Origin + new xyz(0, Size.y, 0));



            Vertex3d        E      = new Vertex3d(A.Value + new xyz(0, 0, Size.z));
            Vertex3d        F      = new Vertex3d(B.Value + new xyz(0, 0, Size.z));
            Vertex3d        G      = new Vertex3d(C.Value + new xyz(0, 0, Size.z));
            Vertex3d        H      = new Vertex3d(D.Value + new xyz(0, 0, Size.z));
            Vertex3dArray_2 Border = new Vertex3dArray_2();
            Vertex3dArray   VA     = new Vertex3dArray();

            Border.Add(VA);
            Face Face = null;

            VA.Clear();
            VA.Add(A);
            VA.Add(B);
            VA.Add(C);
            VA.Add(D);
            Face = Face.SolidPlane(Box, Border);
            Box.FaceList.Add(Face);

            VA.Clear();
            VA.Add(A);
            VA.Add(E);
            VA.Add(F);
            VA.Add(B);

            Face = Face.SolidPlane(Box, Border);
            Box.FaceList.Add(Face);

            VA.Clear();
            VA.Add(B);
            VA.Add(F);
            VA.Add(G);
            VA.Add(C);
            Face = Face.SolidPlane(Box, Border);
            Box.FaceList.Add(Face);

            VA.Clear();
            VA.Add(C);
            VA.Add(G);
            VA.Add(H);
            VA.Add(D);
            Face = Face.SolidPlane(Box, Border);
            Box.FaceList.Add(Face);

            VA.Clear();
            VA.Add(D);
            VA.Add(H);
            VA.Add(E);
            VA.Add(A);
            Face = Face.SolidPlane(Box, Border);
            Box.FaceList.Add(Face);

            VA.Clear();
            VA.Add(H);
            VA.Add(G);
            VA.Add(F);
            VA.Add(E);
            Face = Face.SolidPlane(Box, Border);
            Box.FaceList.Add(Face);
            return(Box);
        }
示例#11
0
        /// <summary>
        /// creates a <see cref="Face"/> for a <see cref="Solid"/> in the <see cref="Model.Solid"/>.
        /// The Curves are all <see cref="Line3D"/>. The <see cref="Face"/> is plane and has as <see cref="Face.Surface"/> a <see cref="PlaneSurface"/>.
        /// </summary>
        /// <param name="Solid">is the target in which the <see cref="Face"/> will be posed.</param>
        /// <param name="Bounds">contains the <see cref="Vertex3d"/> for the <see cref="Line3D"/>.</param>
        /// <returns>a <see cref="Face"/></returns>
        public static Face SolidPlane(Solid Solid, Vertex3dArray_2 Bounds)
        {
            if (Bounds.Count == 0)
            {
                return(null);
            }
            xyz N = new xyz(0, 0, 0);
            xyz P = Bounds[0][0].Value;

            for (int i = 1; i < Bounds[0].Count - 1; i++)
            {
                xyz A = Bounds[0][i].Value;
                xyz B = Bounds[0][i + 1].Value;
                xyz M = N;
                N = N + ((A - P) & (B - P));
            }
            N = N.normalized() * (-1);
            Base Base = Base.UnitBase;

            Base.BaseO = P;
            Base.BaseZ = N;
            if ((Base.BaseZ & new xyz(1, 0, 0)).dist(xyz.Null) > 0.01)
            {
                Base.BaseY = (Base.BaseZ & (new xyz(1, 0, 0))).normalized();
                Base.BaseX = Base.BaseY & Base.BaseZ;
            }
            else
            {
                Base.BaseY = (Base.BaseZ & (new xyz(0, 1, 0))).normalized();
                Base.BaseX = Base.BaseY & Base.BaseZ;
            }

            PlaneSurface Surface = new PlaneSurface();

            Surface.Base = Base;
            //-------------------------------------
            //-------- Create the Face
            Face Result = new Face();

            // ---- With Plane Surface
            Result.Surface = Surface;
            if (Solid != null)
            {
                Solid.FaceList.Add(Result);
            }
            //----- Set the Edges
            for (int i = 0; i < Bounds.Count; i++)
            {
                EdgeLoop Edgeloop = new EdgeLoop();
                Result.Bounds.Add(Edgeloop);
                for (int j = 0; j < Bounds[i].Count; j++)
                {
                    Vertex3d A = Bounds[i][j];
                    Vertex3d B = null;
                    if (j == Bounds[i].Count - 1)
                    {
                        B = Bounds[i][0];
                    }
                    else
                    {
                        B = Bounds[i][j + 1];
                    }
                    Edge E = Edge.SolidEdge(Solid, Result, A, B, new Line3D(A.Value, B.Value));

                    Edgeloop.Add(E);
                }
            }

            Result.RefreshParamCurves();
            return(Result);
        }
示例#12
0
        /// <summary>
        /// overrides <see cref="Solid.Refresh"/>.
        /// </summary>
        public override void Refresh()
        {
            Clear();
            Torus TorusSurface = new Torus();

            TorusSurface.VResolution = VResolution;
            TorusSurface.UResolution = UResolution;

            TorusSurface.InnerRadius = InnerRadius;
            TorusSurface.OuterRadius = OuterRadius;

            Vertex3d[,] Points = new Vertex3d[TorusSurface.UResolution, TorusSurface.VResolution];
            xyz[,] Normals     = new xyz[TorusSurface.UResolution, TorusSurface.VResolution];

            Line3D[,] HorzCurves = new Line3D[TorusSurface.UResolution, TorusSurface.VResolution];
            Line3D[,] VertCurves = new Line3D[TorusSurface.UResolution, TorusSurface.VResolution];

            for (int i = 0; i < TorusSurface.UResolution; i++)
            {
                for (int j = 0; j < TorusSurface.VResolution; j++)
                {
                    Normals[i, j] = TorusSurface.Normal(((float)i / (float)TorusSurface.UResolution), (float)j / (float)TorusSurface.VResolution);

                    Points[i, j] = new Vertex3d(TorusSurface.Value((float)i / (float)TorusSurface.UResolution, (float)j / (float)TorusSurface.VResolution));
                    VertexList.Add(Points[i, j]);
                }
            }
            for (int i = 0; i < TorusSurface.UResolution; i++)
            {
                for (int j = 0; j < TorusSurface.VResolution; j++)
                {
                    if (i + 1 < TorusSurface.UResolution)
                    {
                        HorzCurves[i, j] = new Line3D(Points[i, j].Value, Points[i + 1, j].Value);
                    }
                    else
                    {
                        HorzCurves[i, j] = new Line3D(Points[i, j].Value, Points[0, j].Value);
                    }
                    HorzCurves[i, j].Neighbors = new Face[2];

                    EdgeCurveList.Add(HorzCurves[i, j]);

                    if (j + 1 < TorusSurface.VResolution)
                    {
                        VertCurves[i, j] = new Line3D(Points[i, j].Value, Points[i, j + 1].Value);
                    }
                    else
                    {
                        VertCurves[i, j] = new Line3D(Points[i, j].Value, Points[i, 0].Value);
                    }
                    VertCurves[i, j].Neighbors = new Face[2];

                    EdgeCurveList.Add(VertCurves[i, j]);
                }
            }

            for (int i = 0; i < TorusSurface.UResolution; i++)
            {
                for (int j = 0; j < TorusSurface.VResolution; j++)
                {
                    int jIndex = -1;
                    if (j + 1 < TorusSurface.VResolution)
                    {
                        jIndex = j + 1;
                    }
                    else
                    {
                        jIndex = 0;
                    }
                    int iIndex = -1;
                    if (i + 1 < TorusSurface.UResolution)
                    {
                        iIndex = i + 1;
                    }
                    else
                    {
                        iIndex = 0;
                    }
                    Vertex3d A = Points[i, j];
                    Vertex3d B = null;
                    B = Points[i, jIndex];
                    Vertex3d C = null;
                    C = Points[iIndex, jIndex];
                    Vertex3d D = null;
                    D = Points[iIndex, j];
                    Face F = new Face();
                    FaceList.Add(F);
                    F.Surface = new SmoothPlane(Points[i, j].Value, Points[iIndex, jIndex].Value, Points[i, jIndex].Value, Points[iIndex, j].Value, Normals[i, j], Normals[iIndex, jIndex], Normals[i, jIndex], Normals[iIndex, j]);;
                    EdgeLoop EL = new EdgeLoop();
                    F.Bounds.Add(EL);

                    if (A != B)
                    {
                        Edge E = new Edge();
                        EdgeList.Add(E);
                        EL.Add(E);
                        E.EdgeStart = A;
                        E.EdgeEnd   = B;
                        E.EdgeCurve = VertCurves[i, j];

                        E.EdgeCurve.Neighbors[0] = F;
                        E.SameSense  = true;
                        E.ParamCurve = F.Surface.To2dCurve(E.EdgeCurve);
                    }
                    else
                    {
                    }
                    if (B != C)
                    {
                        Edge E = new Edge();
                        EL.Add(E);
                        EdgeList.Add(E);
                        E.EdgeStart = B;
                        E.EdgeEnd   = C;
                        if (j + 1 < TorusSurface.VResolution)
                        {
                            E.EdgeCurve = HorzCurves[i, j + 1];
                        }
                        else
                        {
                            E.EdgeCurve = HorzCurves[i, 0];
                        }
                        if (E.EdgeCurve.A.dist(B.Value) > 0.001)
                        {
                        }
                        E.EdgeCurve.Neighbors[0] = F;

                        E.SameSense  = true;
                        E.ParamCurve = F.Surface.To2dCurve(E.EdgeCurve);
                    }
                    else
                    {
                    }


                    if (C != D)
                    {
                        Edge E = new Edge();
                        EL.Add(E);
                        EdgeList.Add(E);
                        E.EdgeStart = C;
                        E.EdgeEnd   = D;
                        if (i + 1 < TorusSurface.UResolution)
                        {
                            E.EdgeCurve = VertCurves[i + 1, j];
                        }
                        else
                        {
                            E.EdgeCurve = VertCurves[0, j];
                        }
                        E.EdgeCurve.Neighbors[1] = F;
                        E.SameSense  = false;
                        E.ParamCurve = F.Surface.To2dCurve(E.EdgeCurve);
                        E.ParamCurve.Invert();
                    }
                    else
                    {
                    }
                    if (A != D)
                    {
                        Edge E = new Edge();
                        EL.Add(E);

                        EdgeList.Add(E);
                        E.EdgeStart = D;
                        E.EdgeEnd   = A;
                        E.EdgeCurve = HorzCurves[i, j];
                        E.EdgeCurve.Neighbors[1] = F;
                        E.SameSense  = false;
                        E.ParamCurve = F.Surface.To2dCurve(E.EdgeCurve);
                        E.ParamCurve.Invert();
                    }
                    else
                    {
                    }
                }
            }

            RefreshParamCurves();
        }
示例#13
0
        /// <summary>
        /// activates a <b>CatMull</b> division.
        /// </summary>
        public void CatMull()
        {
            for (int i = 0; i < VertexList.Count; i++)
            {
                Vertex3d V = VertexList[i];
                V.Tag = new SubDivisionDescriptor();
            }

            for (int i = 0; i < FaceList.Count; i++)
            {
                Face F = FaceList[i];
                F.DrawRelativToSurfaceBase = false;
                int n = 0;
                for (int j = 0; j < F.Bounds.Count; j++)
                {
                    xyz      subDivCenter = new xyz(0, 0, 0);
                    EdgeLoop EL           = F.Bounds[j];
                    for (int k = 0; k < EL.Count; k++)
                    {
                        n++;
                        Edge E = EL[k];


                        subDivCenter = subDivCenter + E.EdgeStart.Value;
                    }
                    F.Tag = subDivCenter * (1f / (float)EL.Count);
                }
            }

            for (int i = 0; i < FaceList.Count; i++)
            {
                Face F = FaceList[i];

                int n = 0;
                for (int j = 0; j < F.Bounds.Count; j++)
                {
                    EdgeLoop EL = F.Bounds[j];
                    for (int k = 0; k < EL.Count; k++)
                    {
                        n++;
                        Edge E        = EL[k];
                        Face Neighbor = null;
                        if (E.SameSense)
                        {
                            Neighbor = E.EdgeCurve.Neighbors[1] as Face;
                        }
                        else
                        {
                            Neighbor = E.EdgeCurve.Neighbors[0] as Face;
                        }
                        E.Tag = ((xyz)(E.EdgeCurve.Neighbors[1] as Face).Tag + (xyz)(E.EdgeCurve.Neighbors[0] as Face).Tag + E.EdgeStart.Value + E.EdgeEnd.Value) * (1f / 4f);
                        // Mittelwert der Facepunkte und der Anfangs und Endpunkte im Tag speichern
                        //     E.Tag = ((xyz)F.Tag + (xyz)Neighbor.Tag + E.EdgeStart.Value + E.EdgeEnd.Value) * 0.25;
                        //
                        // den Descriptor im Vertex E.EdgeEnd.Tag updaten
                        SubDivisionDescriptor SDD = E.EdgeEnd.Tag as SubDivisionDescriptor;
                        SDD.Edges.Add(E);
                        SDD.Faces.Add(F);
                    }
                }
            }

            // Update Vertixlist
            xyz Q = new xyz(0, 0, 0);
            xyz R = new xyz(0, 0, 0);

            for (int i = 0; i < VertexList.Count; i++)
            {
                Vertex3d V = VertexList[i];
                SubDivisionDescriptor SDV = V.Tag as SubDivisionDescriptor;
                int n = SDV.Faces.Count;
                if (n == 0)
                {
                    return;
                }
                Q = new xyz(0, 0, 0);
                R = new xyz(0, 0, 0);
                for (int j = 0; j < SDV.Faces.Count; j++)
                {
                    Q = (xyz)SDV.Faces[j].Tag + Q;
                }
                Q = Q * (1f / (float)SDV.Faces.Count);


                for (int j = 0; j < SDV.Edges.Count; j++)
                {
                    R = (xyz)SDV.Edges[j].Tag + R;
                }
                R = R * (1f / (float)SDV.Edges.Count);

                xyz S = V.Value;
                V.Value = (Q + R * 2 + S * (n - 3)) * (1f / (float)n);
            }

            // Kanten Ersetzen
            for (int i = 0; i < FaceList.Count; i++)
            {
                Face F = FaceList[i];



                for (int j = 0; j < F.Bounds.Count; j++)
                {
                    EdgeLoop EL = F.Bounds[j];
                    for (int k = 0; k < EL.Count; k++)
                    {
                        Edge E = EL[k];

                        if (E.SameSense)
                        {
                            E.EdgeCurve.A = E.EdgeStart.Value;
                            E.EdgeCurve.B = E.EdgeEnd.Value;
                        }
                    }
                }
            }

            // Kanten Ersetzen
            for (int i = 0; i < FaceList.Count; i++)
            {
                Face F = FaceList[i];



                for (int j = 0; j < F.Bounds.Count; j++)
                {
                    EdgeLoop EL = F.Bounds[j];
                    for (int k = 0; k < EL.Count; k++)
                    {
                        Edge E = EL[k];
                        if (E.SameSense)
                        {
                            Vertex3d V = new Vertex3d((xyz)E.Tag);

                            insertVertexToSameSenseEdge(F, j, k, V);
                            k++;
                        }
                    }
                }
            }

            FaceList Temp = new FaceList();

            for (int i = 0; i < FaceList.Count; i++)
            {
                Face F = FaceList[i];
                for (int x = 0; x < F.Bounds.Count; x++)
                {
                    EdgeLoop EL = F.Bounds[x];



                    Edge E2 = null;

                    Vertex3d V1 = new Vertex3d();
                    V1.Value = (xyz)F.Tag;
                    VertexList.Add(V1);


                    Vertex3d V4 = null;
                    Vertex3d V2 = null;



                    int startIndex = 1;
                    if (EL[0].EdgeStart.Tag == null) // StartPunkt ist eingefügt
                    {
                        startIndex = 0;
                    }

                    int id = startIndex;

                    int  counter = 0;
                    Edge First   = null;
                    Edge Last    = null;
                    while (id >= 0)
                    {
                        counter++;
                        EdgeLoop newEl = new EdgeLoop();

                        V2 = EL[id].EdgeStart;


                        if (id + 1 < EL.Count)
                        {
                            V4 = EL[id + 1].EdgeEnd;
                        }
                        else
                        {
                            V4 = EL[0].EdgeEnd;
                        }
                        Face newF = new Face();
                        newF.Parent = F.Parent;
                        Temp.Add(newF);


                        EdgeLoop   ELF = new EdgeLoop();
                        List <xyz> Pt  = new List <xyz>();
                        newF.Surface = new PlaneSurface(V1.Value, V2.Value, V4.Value);
                        //    newF.Surface = new PlaneSurface(V1.Value, V2.Value, V4.Value);
                        Edge EA = new Edge();
                        ELF.Add(EA);
                        EdgeList.Add(EA);
                        EA.EdgeStart = V1;
                        EA.EdgeEnd   = V2;
                        if (Last == null)
                        {
                            EA.EdgeCurve = new Line3D(V1.Value, V2.Value);
                            Pt.Add(V1.Value);
                            EdgeCurveList.Add(EA.EdgeCurve);
                            EA.EdgeCurve.Neighbors    = new Face[2];
                            EA.SameSense              = true;
                            EA.EdgeCurve.Neighbors[0] = newF;
                            if (id == startIndex)
                            {
                                First = EA;
                            }
                        }
                        else
                        {
                            EA.EdgeStart = Last.EdgeEnd;
                            Pt.Add(EA.EdgeStart.Value);
                            EA.EdgeEnd   = Last.EdgeStart;
                            EA.EdgeCurve = Last.EdgeCurve;
                            EA.EdgeCurve.Neighbors[1] = newF;
                            EA.SameSense = false;
                        }


                        newF.Bounds.Add(ELF);

                        E2 = EL[id];

                        if (E2.SameSense)
                        {
                            E2.EdgeCurve.Neighbors[0] = newF;
                        }
                        else
                        {
                            E2.EdgeCurve.Neighbors[1] = newF;
                        }
                        Pt.Add(E2.EdgeStart.Value);
                        ELF.Add(E2);


                        Edge E3 = null;
                        if (id + 1 < EL.Count)
                        {
                            E3 = EL[id + 1];
                        }
                        else
                        {
                            E3 = EL[0];
                        }
                        Pt.Add(E3.EdgeStart.Value);
                        if (E3.SameSense)
                        {
                            E3.EdgeCurve.Neighbors[0] = newF;
                        }
                        else
                        {
                            E3.EdgeCurve.Neighbors[1] = newF;
                        }



                        ELF.Add(E3);



                        Edge EE = new Edge();
                        EdgeList.Add(EE);
                        EE.EdgeStart = V4;
                        EE.EdgeEnd   = V1;
                        ELF.Add(EE);
                        Pt.Add(V4.Value);


                        if (counter < 4)
                        {
                            EE.EdgeCurve = new Line3D(EE.EdgeStart.Value, EE.EdgeEnd.Value);
                            EdgeCurveList.Add(EE.EdgeCurve);

                            EE.EdgeCurve.Neighbors    = new Face[2];
                            EE.EdgeCurve.Neighbors[0] = newF;
                            EE.SameSense = true;
                        }
                        else
                        {
                            EE.EdgeCurve = First.EdgeCurve;
                            EE.EdgeStart = First.EdgeEnd;
                            EE.EdgeEnd   = First.EdgeStart;
                            EE.EdgeCurve.Neighbors[1] = newF;
                            EE.SameSense = false;
                        }
                        Last = EE;



                        id++;
                        id++;
                        // newF.Surface = new SmoothPlane(Pt[0],Pt[1],Pt[2],Pt[3], new xyz(1, 0, 0), new xyz(1, 0, 0), new xyz(1, 0, 0), new xyz(1, 0, 0));
                        //     newF.Surface = new SmoothPlane(Pt[0], Pt[1], Pt[2], Pt[3], (Pt[0] - Pt[1]) & (Pt[0] - Pt[3]), (Pt[1] - Pt[0]) & (Pt[1] - Pt[2]), (Pt[2] - Pt[1]) & (Pt[3] - Pt[1]), (Pt[0] - Pt[3]) & (Pt[2] - Pt[3]));
                        if (id + 1 > EL.Count)
                        {
                            break;
                        }

                        //   newF.Surface = new PlaneSurface(V1.Value, V2.Value, V4.Value);
                    }
                }
            }
            FaceList = Temp;
            for (int i = 0; i < FaceList.Count; i++)
            {
                Face F = FaceList[i];
                F.Surface.BoundedCurves = new Loca();
                List <xyz> P  = new List <xyz>();
                xyz        P1 = new xyz(0, 0, 0);
                xyz        P2 = new xyz(0, 0, 0);
                xyz        P3 = new xyz(0, 0, 0);
                xyz        P4 = new xyz(0, 0, 0);

                for (int k = 0; k < F.Bounds.Count; k++)
                {
                    CurveArray CA = new CurveArray();
                    F.Surface.BoundedCurves.Add(CA);
                    for (int l = 0; l < F.Bounds[k].Count; l++)
                    {
                        Edge E = F.Bounds[k][l];

                        CA.Add(new Line(F.Surface.ProjectPoint(E.EdgeStart.Value), F.Surface.ProjectPoint(E.EdgeEnd.Value)));
                        if (l < 4)
                        {
                            P.Add(E.EdgeStart.Value);
                        }
                    }
                    if (i == 3)
                    {
                        List <Edge> L1 = new List <Edge>();
                        for (int j = 0; j < 3; j++)
                        {
                            for (int m = 0; m < FaceList[j].Bounds.Count; m++)
                            {
                                xyz A = new xyz(0, 0, 0);
                                for (int h = 0; h < FaceList[j].Bounds[m].Count; h++)
                                {
                                    Edge E = FaceList[j].Bounds[m][h];

                                    L1.Add(E);
                                }
                            }
                        }

                        for (int h = 0; h < L1.Count; h++)
                        {
                            for (int m = 0; m < L1.Count; m++)
                            {
                                if ((L1[h].EdgeStart.Value.dist(L1[m].EdgeStart.Value) < 0.001) && (h != m))
                                {
                                }
                            }
                        }
                    }
                }

                xyz  n  = ((P[2] - P[0]) & (P[1] - P[0]));
                xyz  m1 = ((P[3] - P[0]) & (P[2] - P[0]));
                Loca L  = F.Surface.BoundedCurves;
                if (i / 2 * 2 == i)
                {
                    F.Surface = new SmoothPlane(P[0], P[1], P[2], P[3], n);
                }
                else
                {
                    F.Surface = new SmoothPlane(P[0], P[1], P[2], P[3], m1);
                }
                F.Surface.BoundedCurves = L;



                //   (P[1] - P[0]) & (P[1] - P[2]), (P[2] - P[1]) & (P[2] - P[3]), (P[3] - P[0]) & (P[3] - P[2]));
                F.DrawRelativToSurfaceBase = false;
            }
        }
示例#14
0
        /// <summary>
        /// overrides <see cref="Solid.Refresh()"/>.
        /// </summary>
        public override void Refresh()
        {
            Clear();
            Cone ConeSurface = new Cone();

            ConeSurface.VResolution = VResolution;
            ConeSurface.UResolution = UResolution;


            ConeSurface.Radius    = Radius;
            ConeSurface.HalfAngle = HalfAngle;
            ConeSurface.Height    = Height;
            Vertex3d[,] Points    = new Vertex3d[ConeSurface.UResolution, ConeSurface.VResolution + 1];
            Line3D[,] HorzCurves  = new Line3D[ConeSurface.UResolution, ConeSurface.VResolution + 1];
            Line3D[,] VertCurves  = new Line3D[ConeSurface.UResolution, ConeSurface.VResolution];
            Vertex3d[,] Normals   = new Vertex3d[ConeSurface.UResolution + 1, ConeSurface.VResolution + 1];

            for (int i = 0; i < ConeSurface.UResolution; i++)
            {
                for (int j = 0; j <= ConeSurface.VResolution; j++)
                {
                    Points[i, j] = new Vertex3d(ConeSurface.Value((float)i / (float)ConeSurface.UResolution, (float)j / (float)ConeSurface.VResolution));
                    VertexList.Add(Points[i, j]);
                    Normals[i, j] = new Vertex3d(ConeSurface.Normal((float)i / (float)ConeSurface.UResolution, (float)j / (float)ConeSurface.VResolution));
                }
            }
            for (int i = 0; i < ConeSurface.UResolution; i++)
            {
                for (int j = 0; j <= ConeSurface.VResolution; j++)
                {
                    if (i < ConeSurface.UResolution)
                    {
                        if (i + 1 < ConeSurface.UResolution)
                        {
                            HorzCurves[i, j] = new Line3D(Points[i, j].Value, Points[i + 1, j].Value);
                        }
                        else
                        {
                            HorzCurves[i, j] = new Line3D(Points[i, j].Value, Points[0, j].Value);
                        }
                        HorzCurves[i, j].Neighbors = new Face[2];
                        EdgeCurveList.Add(HorzCurves[i, j]);
                    }
                    if (j < ConeSurface.VResolution)
                    {
                        VertCurves[i, j]           = new Line3D(Points[i, j].Value, Points[i, j + 1].Value);
                        VertCurves[i, j].Neighbors = new Face[2];
                        EdgeCurveList.Add(VertCurves[i, j]);
                    }
                }
            }

            for (int i = 0; i < ConeSurface.UResolution; i++)
            {
                for (int j = 0; j < ConeSurface.VResolution; j++)
                {
                    int      IInd = -1;
                    Vertex3d A    = Points[i, j];
                    Vertex3d B    = Points[i, j + 1];

                    Vertex3d C = null;
                    if (i + 1 < ConeSurface.UResolution)
                    {
                        IInd = i + 1;
                        C    = Points[i + 1, j + 1];
                    }
                    else
                    {
                        IInd = 0;
                        C    = Points[0, j + 1];
                    }
                    Vertex3d D = null;
                    if (i + 1 < ConeSurface.UResolution)
                    {
                        D = Points[i + 1, j];
                    }
                    else
                    {
                        D = Points[0, j];
                    }


                    Face F = new Face();
                    FaceList.Add(F);

                    F.Surface = new SmoothPlane(Points[i, j].Value, Points[IInd, j].Value, Points[i, j + 1].Value, Points[IInd, j + 1].Value,
                                                Normals[i, j].Value, Normals[IInd, j + 1].Value, Normals[i, j + 1].Value, Normals[IInd, j].Value);

                    EdgeLoop EL = new EdgeLoop();
                    F.Bounds.Add(EL);

                    Edge E = new Edge();
                    EdgeList.Add(E);
                    EL.Add(E);
                    E.EdgeStart = A;
                    E.EdgeEnd   = B;
                    E.EdgeCurve = VertCurves[i, j];

                    E.EdgeCurve.Neighbors[0] = F;
                    E.SameSense  = true;
                    E.ParamCurve = F.Surface.To2dCurve(E.EdgeCurve);

                    E = new Edge();
                    EL.Add(E);
                    EdgeList.Add(E);
                    E.EdgeStart = B;
                    E.EdgeEnd   = C;
                    E.EdgeCurve = HorzCurves[i, j + 1];
                    E.EdgeCurve.Neighbors[0] = F;

                    E.SameSense  = true;
                    E.ParamCurve = F.Surface.To2dCurve(E.EdgeCurve);
                    E            = new Edge();
                    EL.Add(E);
                    EdgeList.Add(E);
                    E.EdgeStart = C;
                    E.EdgeEnd   = D;
                    if (i + 1 < ConeSurface.UResolution)
                    {
                        E.EdgeCurve = VertCurves[i + 1, j];
                    }
                    else
                    {
                        E.EdgeCurve = VertCurves[0, j];
                    }
                    E.EdgeCurve.Neighbors[1] = F;
                    E.SameSense  = false;
                    E.ParamCurve = F.Surface.To2dCurve(E.EdgeCurve);
                    E.ParamCurve.Invert();

                    E = new Edge();
                    EL.Add(E);
                    EdgeList.Add(E);
                    E.EdgeStart = D;
                    E.EdgeEnd   = A;
                    E.EdgeCurve = HorzCurves[i, j];
                    E.EdgeCurve.Neighbors[1] = F;
                    E.SameSense  = false;
                    E.ParamCurve = F.Surface.To2dCurve(E.EdgeCurve);
                    E.ParamCurve.Invert();
                }
            }

            // Boden
            Base BodenBase = Base.From4Points(Points[0, 0].Value, Points[2, 0].Value, Points[1, 0].Value, Points[3, 0].Value);

            //  Base BodenBase = Base.UnitBase;
            BodenBase.BaseO = Points[0, 0].Value;
            {
                Face F = new Face();
                FaceList.Add(F);
                PlaneSurface S = null;
                S         = new PlaneSurface();
                S.Base    = BodenBase;
                F.Surface = S;

                EdgeLoop EL = new EdgeLoop();
                F.Bounds.Add(EL);
                for (int i = 0; i < ConeSurface.UResolution; i++)
                {
                    Edge E = new Edge();
                    EL.Add(E);
                    EdgeList.Add(E);
                    E.EdgeStart = Points[i, 0];
                    if (i + 1 < ConeSurface.UResolution)
                    {
                        E.EdgeEnd = Points[i + 1, 0];
                    }
                    else
                    {
                        E.EdgeEnd = Points[0, 0];
                    }
                    E.EdgeCurve = HorzCurves[i, 0];
                    E.EdgeCurve.Neighbors[0] = F;
                    E.SameSense  = true;
                    E.ParamCurve = S.To2dCurve(E.EdgeCurve);
                }
            }
            // Deckel
            {
                PlaneSurface S = null;
                S = new PlaneSurface();
                BodenBase.BaseO = Points[0, ConeSurface.VResolution].Value;
                //S.Base = BodenBase;
                try
                {
                    S.Base = Base.From4Points(Points[0, ConeSurface.VResolution].Value, Points[2, ConeSurface.VResolution].Value, Points[3, ConeSurface.VResolution].Value, Points[1, ConeSurface.VResolution].Value);
                }
                catch (Exception)
                {
                    Base B = Base.UnitBase;
                    B.BaseO = Points[0, ConeSurface.VResolution].Value;
                    S.Base  = B;
                }
                Face F = new Face();
                FaceList.Add(F);
                F.Surface = S;

                EdgeLoop EL = new EdgeLoop();
                F.Bounds.Add(EL);
                for (int i = ConeSurface.UResolution - 1; i >= 0; i--)
                //   for (int i = 0; i < ConeSurface.UResolution; i++)

                {
                    Edge E = new Edge();
                    EL.Add(E);
                    EdgeList.Add(E);
                    E.EdgeStart = Points[i, ConeSurface.VResolution];
                    //if (i + 1 < ConeSurface.UResolution)
                    //    E.EdgeEnd = Points[i + 1, ConeSurface.VResolution];
                    //else
                    //    E.EdgeEnd = Points[0, ConeSurface.VResolution];
                    E.EdgeEnd = Points[i, ConeSurface.VResolution];
                    if (i + 1 < ConeSurface.UResolution)
                    {
                        E.EdgeStart = Points[i + 1, ConeSurface.VResolution];
                    }
                    else
                    {
                        E.EdgeStart = Points[0, ConeSurface.VResolution];
                    }
                    E.EdgeCurve = HorzCurves[i, ConeSurface.VResolution];
                    if (E.EdgeStart.Value.dist(E.EdgeCurve.B) > 0.001)
                    {
                    }
                    E.EdgeCurve.Neighbors[1] = F;
                    E.SameSense  = false;
                    E.ParamCurve = S.To2dCurve(E.EdgeCurve);
                    E.ParamCurve.Invert();
                }
            }
            RefreshParamCurves();

            base.Refresh();
        }
示例#15
0
        /// <summary>
        /// overrides <see cref="Solid.Refresh"/>.
        /// </summary>
        public override void Refresh()
        {
            Clear();
            Sphere SphereSurface = new Sphere();

            SphereSurface.VResolution = VResolution;
            SphereSurface.UResolution = UResolution;

            SphereSurface.Radius = Radius;
            Vertex3d NP = new Vertex3d(new xyz(0, 0, Radius));
            Vertex3d SP = new Vertex3d(new xyz(0, 0, -Radius));

            Vertex3d[,] Points   = new Vertex3d[SphereSurface.UResolution + 1, SphereSurface.VResolution + 1];
            Line3D[,] HorzCurves = new Line3D[SphereSurface.UResolution, SphereSurface.VResolution];
            Line3D[,] VertCurves = new Line3D[SphereSurface.UResolution, SphereSurface.VResolution];
            xyz[,] Normals       = new xyz[SphereSurface.UResolution + 1, SphereSurface.VResolution + 1];
            VertexList.Add(NP);
            VertexList.Add(SP);
            for (int i = 0; i < SphereSurface.UResolution + 1; i++)
            {
                for (int j = 0; j < SphereSurface.VResolution + 1; j++)
                {
                    Normals[i, j] = SphereSurface.Normal(((float)i / (float)SphereSurface.UResolution), (float)j / (float)SphereSurface.VResolution);

                    if (j == 0)
                    {
                        Points[i, j] = SP; continue;
                    }
                    if (j == SphereSurface.VResolution)
                    {
                        Points[i, j] = NP; continue;
                    }
                    if (i == SphereSurface.UResolution)
                    {
                        Points[i, j] = Points[0, j]; continue;
                    }
                    Points[i, j] = new Vertex3d(SphereSurface.Value((float)i / (float)SphereSurface.UResolution, (float)j / (float)SphereSurface.VResolution));
                    VertexList.Add(Points[i, j]);
                }
            }
            for (int i = 0; i < SphereSurface.UResolution; i++)
            {
                for (int j = 0; j < SphereSurface.VResolution; j++)
                {
                    if (i < SphereSurface.UResolution)
                    {
                        if (i + 1 < SphereSurface.UResolution)
                        {
                            HorzCurves[i, j] = new Line3D(Points[i, j].Value, Points[i + 1, j].Value);
                        }
                        else
                        {
                            HorzCurves[i, j] = new Line3D(Points[i, j].Value, Points[0, j].Value);
                        }
                        HorzCurves[i, j].Neighbors = new Face[2];
                        if (HorzCurves[i, j].A.dist(HorzCurves[i, j].B) > 0.0001)
                        {
                            EdgeCurveList.Add(HorzCurves[i, j]);
                        }
                    }
                    if (j < SphereSurface.VResolution)
                    {
                        VertCurves[i, j]           = new Line3D(Points[i, j].Value, Points[i, j + 1].Value);
                        VertCurves[i, j].Neighbors = new Face[2];

                        EdgeCurveList.Add(VertCurves[i, j]);
                    }
                }
            }
            // if (false)
            for (int i = 0; i < SphereSurface.UResolution; i++)
            {
                for (int j = 0; j < SphereSurface.VResolution; j++)
                {
                    Vertex3d A = Points[i, j];
                    Vertex3d B = Points[i, j + 1];

                    Vertex3d C = null;
                    if (i + 1 < SphereSurface.UResolution)
                    {
                        C = Points[i + 1, j + 1];
                    }
                    else
                    {
                        C = Points[0, j + 1];
                    }

                    Vertex3d D = null;
                    if (i + 1 < SphereSurface.UResolution)
                    {
                        D = Points[i + 1, j];
                    }
                    else
                    {
                        D = Points[0, j];
                    }


                    Face F = new Face();
                    FaceList.Add(F);
                    F.Surface = new SmoothPlane(Points[i, j].Value, Points[i + 1, j + 1].Value, Points[i, j + 1].Value, Points[i + 1, j].Value, Normals[i, j], Normals[i + 1, j + 1], Normals[i, j + 1], Normals[i + 1, j]);;


                    EdgeLoop EL = new EdgeLoop();
                    F.Bounds.Add(EL);

                    if (A != B)
                    {
                        Edge E = new Edge();
                        EdgeList.Add(E);
                        EL.Add(E);
                        E.EdgeStart = A;
                        E.EdgeEnd   = B;
                        E.EdgeCurve = VertCurves[i, j];

                        E.EdgeCurve.Neighbors[0] = F;
                        E.SameSense  = true;
                        E.ParamCurve = F.Surface.To2dCurve(E.EdgeCurve);
                    }
                    if (B != C)
                    {
                        Edge E = new Edge();
                        EL.Add(E);
                        EdgeList.Add(E);
                        E.EdgeStart = B;
                        E.EdgeEnd   = C;
                        if (j + 1 < SphereSurface.VResolution)
                        {
                            E.EdgeCurve = HorzCurves[i, j + 1];
                        }
                        else
                        {
                            E.EdgeCurve = HorzCurves[i, 0];
                        }
                        if (E.EdgeCurve.A.dist(B.Value) > 0.001)
                        {
                        }
                        E.EdgeCurve.Neighbors[0] = F;

                        E.SameSense  = true;
                        E.ParamCurve = F.Surface.To2dCurve(E.EdgeCurve);
                    }


                    if (C != D)
                    {
                        Edge E = new Edge();
                        EL.Add(E);
                        EdgeList.Add(E);
                        E.EdgeStart = C;
                        E.EdgeEnd   = D;
                        if (i + 1 < SphereSurface.UResolution)
                        {
                            E.EdgeCurve = VertCurves[i + 1, j];
                        }
                        else
                        {
                            E.EdgeCurve = VertCurves[0, j];
                        }
                        E.EdgeCurve.Neighbors[1] = F;
                        E.SameSense  = false;
                        E.ParamCurve = F.Surface.To2dCurve(E.EdgeCurve);
                        E.ParamCurve.Invert();
                    }
                    if (A != D)
                    {
                        Edge E = new Edge();
                        EL.Add(E);

                        EdgeList.Add(E);
                        E.EdgeStart = D;
                        E.EdgeEnd   = A;
                        E.EdgeCurve = HorzCurves[i, j];
                        E.EdgeCurve.Neighbors[1] = F;
                        E.SameSense  = false;
                        E.ParamCurve = F.Surface.To2dCurve(E.EdgeCurve);
                        E.ParamCurve.Invert();
                    }
                }
            }

            RefreshParamCurves();
            //      base.Refresh();
            //if (!Check())
            //{
            //}
        }
示例#16
0
 /// <summary>
 /// calls <see cref="SolidEdge(Solid,Face, Vertex3d, Vertex3d,Curve3D)"/> and returns a <see cref="Line3D"/>
 /// Kurve.
 /// </summary>
 /// <param name="Solid"><see cref="Solid"/>, in which the <see cref="Edge"/> should be created.</param>
 /// <param name="Face"><see cref="Face"/>, in which the <see cref="Edge"/> should be created.</param>
 /// <param name="A">start point.</param>
 /// <param name="B">end point.</param>
 /// <returns>an <see cref="Edge"/>.</returns>
 public static Edge SolidEdgeLine(Solid Solid, Face Face, Vertex3d A, Vertex3d B)
 {
     return(SolidEdge(Solid, Face, A, B, new Line3D(A.Value, B.Value)));
 }
示例#17
0
        /// <summary>
        /// overrides the <see cref="Solid.Refresh()"/> method.
        /// </summary>
        public override void Refresh()
        {
            VertexList.Clear();
            EdgeList.Clear();
            FaceList.Clear();
            EdgeCurveList.Clear();

            Vertex3d A = new Vertex3d(xyz.Null);
            Vertex3d B = new Vertex3d(new xyz(Size.x, 0, 0));
            Vertex3d C = new Vertex3d(new xyz(Size.x, Size.y, 0));
            Vertex3d D = new Vertex3d(new xyz(0, Size.y, 0));
            Vertex3d E = new Vertex3d(A.Value + new xyz(0, 0, Size.z));
            Vertex3d F = new Vertex3d(B.Value + new xyz(0, 0, Size.z));
            Vertex3d G = new Vertex3d(C.Value + new xyz(0, 0, Size.z));
            Vertex3d H = new Vertex3d(D.Value + new xyz(0, 0, Size.z));

            VertexList.Add(A);
            VertexList.Add(B);
            VertexList.Add(C);
            VertexList.Add(D);
            VertexList.Add(E);
            VertexList.Add(F);
            VertexList.Add(G);
            VertexList.Add(H);

            Vertex3dArray_2 Border = new Vertex3dArray_2();
            Vertex3dArray   VA     = new Vertex3dArray();

            Border.Add(VA);
            Face Face = null;

            VA.Clear();
            VA.Add(A);
            VA.Add(B);
            VA.Add(C);
            VA.Add(D);
            Face = Face.SolidPlane(this, Border);
            // FaceList.Add(Face);

            VA.Clear();
            VA.Add(A);
            VA.Add(E);
            VA.Add(F);
            VA.Add(B);

            Face = Face.SolidPlane(this, Border);
            // FaceList.Add(Face);

            VA.Clear();
            VA.Add(B);
            VA.Add(F);
            VA.Add(G);
            VA.Add(C);
            Face = Face.SolidPlane(this, Border);
            //  FaceList.Add(Face);

            VA.Clear();
            VA.Add(C);
            VA.Add(G);
            VA.Add(H);
            VA.Add(D);
            Face = Face.SolidPlane(this, Border);
            //  FaceList.Add(Face);

            VA.Clear();
            VA.Add(D);
            VA.Add(H);
            VA.Add(E);
            VA.Add(A);
            Face = Face.SolidPlane(this, Border);
            //   FaceList.Add(Face);

            VA.Clear();
            VA.Add(H);
            VA.Add(G);
            VA.Add(F);
            VA.Add(E);
            Face = Face.SolidPlane(this, Border);
            //for (int i = 0; i < FaceList.Count; i++)
            //{
            //    FaceList[i].DrawRelativToSurfaceBase = false;
            //    FaceList[i].Refresh();
            //}
        }
示例#18
0
        /// <summary>
        /// overrides the <see cref="Solid.Refresh"/> method and creates the extruder from the base <see cref="Loxy"/> and the <see cref="Height"/>.
        /// </summary>
        public override void Refresh()
        {
            if (Polygon.Count == 0)
            {
                return;
            }

            this.VertexList.Clear();
            this.EdgeCurveList.Clear();
            this.FaceList.Clear();


            List <List <Vertex3d> >     DownVertices  = new List <List <Vertex3d> >();
            List <List <Vertex3d> >     UpVertices    = new List <List <Vertex3d> >();
            List <List <Curve3D> >      VertCurves    = new List <List <Curve3D> >();
            List <List <Curve3D> >      DownCurves    = new List <List <Curve3D> >();
            List <List <Curve3D> >      UpCurves      = new List <List <Curve3D> >();
            List <List <PlaneSurface> > PlaneSurfaces = new List <List <PlaneSurface> >();

            for (int i = 0; i < _Polygon.Count; i++)
            {
                DownVertices.Add(new List <Vertex3d>());
                UpVertices.Add(new List <Vertex3d>());

                VertCurves.Add(new List <Curve3D>());
                DownCurves.Add(new List <Curve3D>());
                UpCurves.Add(new List <Curve3D>());



                PlaneSurfaces.Add(new List <PlaneSurface>());
                for (int j = 0; j < _Polygon[i].Count; j++)
                {
                    if (_Polygon[i][0].dist(_Polygon[i][_Polygon[i].Count - 1]) < 0.00001)
                    {
                        _Polygon[i].RemoveAt(_Polygon[i].Count - 1);
                    }
                }
                for (int j = 0; j < _Polygon[i].Count; j++)
                {
                    Vertex3d V = new Vertex3d(new xyz(_Polygon[i][j].x, _Polygon[i][j].y, 0));
                    VertexList.Add(V);

                    DownVertices[i].Add(V);
                    Curve3D C = null;
                    if (j < _Polygon[i].Count - 1)
                    {
                        C = new Line3D(new xyz(_Polygon[i][j].x, _Polygon[i][j].y, 0), new xyz(_Polygon[i][j + 1].x, _Polygon[i][j + 1].y, 0));
                    }
                    else
                    {
                        C = new Line3D(new xyz(_Polygon[i][j].x, _Polygon[i][j].y, 0), new xyz(_Polygon[i][0].x, _Polygon[i][0].y, 0));
                    }
                    DownCurves[i].Add(C);
                    if (!EdgeCurveList.Contains(C))
                    {
                        this.EdgeCurveList.Add(C);
                    }

                    if (j < _Polygon[i].Count - 1)
                    {
                        C = new Line3D(new xyz(_Polygon[i][j].x, _Polygon[i][j].y, Height), new xyz(_Polygon[i][j + 1].x, _Polygon[i][j + 1].y, Height));
                    }
                    else
                    {
                        C = new Line3D(new xyz(_Polygon[i][j].x, _Polygon[i][j].y, Height), new xyz(_Polygon[i][0].x, _Polygon[i][0].y, Height));
                    }
                    UpCurves[i].Add(C);
                    if (!EdgeCurveList.Contains(C))
                    {
                        EdgeCurveList.Add(C);
                    }

                    V = new Vertex3d(new xyz(_Polygon[i][j].x, _Polygon[i][j].y, Height));
                    UpVertices[i].Add(V);
                    VertexList.Add(V);

                    C = new Line3D(new xyz(_Polygon[i][j].x, _Polygon[i][j].y, 0), new xyz(_Polygon[i][j].x, _Polygon[i][j].y, Height));
                    VertCurves[i].Add(C);
                    if (!EdgeCurveList.Contains(C))
                    {
                        EdgeCurveList.Add(C);
                    }
                    if (j < _Polygon[i].Count - 1)
                    {
                        PlaneSurfaces[i].Add(new PlaneSurface(new xyz(_Polygon[i][j].x, _Polygon[i][j].y, 0),
                                                              new xyz(_Polygon[i][j + 1].x, _Polygon[i][j + 1].y, 0),
                                                              new xyz(_Polygon[i][j + 1].x, _Polygon[i][j + 1].y, Height)
                                                              ));
                    }
                    else
                    {
                        PlaneSurfaces[i].Add(new PlaneSurface(new xyz(_Polygon[i][j].x, _Polygon[i][j].y, 0),
                                                              new xyz(_Polygon[i][0].x, _Polygon[i][0].y, 0),
                                                              new xyz(_Polygon[i][0].x, _Polygon[i][0].y, Height)
                                                              ));
                    }
                }
            }



            for (int i = 0; i < _Polygon.Count; i++)
            {
                for (int j = 0; j < _Polygon[i].Count; j++)
                {
                    Face Face = new Face();
                    FaceList.Add(Face);
                    Face.Surface = PlaneSurfaces[i][j];
                    Face.Bounds  = new Bounds();
                    EdgeLoop Loop = new EdgeLoop();
                    Face.Bounds.Add(Loop);

                    // Von unten nach oben
                    Edge E = new Edge();
                    EdgeList.Add(E);
                    E.EdgeStart = DownVertices[i][j];
                    E.EdgeEnd   = UpVertices[i][j];
                    E.EdgeCurve = VertCurves[i][j];
                    E.SameSense = true;
                    if (j > 0)
                    {
                        VertCurves[i][j].Neighbors[1] = Face;
                    }
                    else
                    {
                        VertCurves[i][0].Neighbors    = new Face[2];
                        VertCurves[i][j].Neighbors[1] = Face;
                    }

                    Loop.Add(E);

                    // Oben
                    E = new Edge();
                    EdgeList.Add(E);
                    E.SameSense = true;
                    E.EdgeStart = UpVertices[i][j];
                    if (j < _Polygon[i].Count - 1)
                    {
                        E.EdgeEnd = UpVertices[i][j + 1];
                    }
                    else
                    {
                        E.EdgeEnd = UpVertices[i][0];
                    }
                    E.EdgeCurve              = UpCurves[i][j];
                    E.EdgeCurve.Neighbors    = new Face[2];
                    E.EdgeCurve.Neighbors[0] = Face;
                    Loop.Add(E);

                    // Rechts nach unten
                    E = new Edge();
                    EdgeList.Add(E);
                    int n = j + 1;
                    if (n == _Polygon[i].Count)
                    {
                        n = 0;
                    }
                    E.EdgeStart = UpVertices[i][n];
                    E.EdgeEnd   = DownVertices[i][n];
                    E.EdgeCurve = VertCurves[i][n];
                    if (j < _Polygon[i].Count - 1)
                    {
                        E.EdgeCurve.Neighbors = new Face[2];
                    }
                    E.EdgeCurve.Neighbors[0] = Face;
                    E.SameSense = false;
                    Loop.Add(E);

                    // unten nach links
                    E = new Edge();
                    EdgeList.Add(E);
                    if (j < _Polygon[i].Count - 1)
                    {
                        E.EdgeStart = DownVertices[i][j + 1];
                    }
                    else
                    {
                        E.EdgeStart = DownVertices[i][0];
                    }
                    E.EdgeEnd                = DownVertices[i][j];
                    E.EdgeCurve              = DownCurves[i][j];
                    E.EdgeCurve.Neighbors    = new Face[2];
                    E.EdgeCurve.Neighbors[0] = Face;
                    E.SameSense              = false;
                    Loop.Add(E);
                }
            }


            // Boden

            Face _Face = new Face();

            FaceList.Add(_Face);
            //    Face.Surface = PlaneSurfaces[i][j];
            _Face.Bounds  = new Bounds();
            _Face.Surface = new PlaneSurface(DownVertices[0][0].Value, DownVertices[0][2].Value, DownVertices[0][1].Value);
            for (int i = 0; i < _Polygon.Count; i++)
            {
                EdgeLoop Loop = new EdgeLoop();
                _Face.Bounds.Add(Loop);
                for (int j = 0; j < _Polygon[i].Count; j++)
                {
                    // Von unten nach oben
                    Edge E = new Edge();
                    EdgeList.Add(E);
                    E.EdgeStart = DownVertices[i][j];
                    if (j + 1 < _Polygon[i].Count)
                    {
                        E.EdgeEnd = DownVertices[i][j + 1];
                    }
                    else
                    {
                        E.EdgeEnd = DownVertices[i][0];
                    }
                    E.EdgeCurve = DownCurves[i][j];
                    E.SameSense = true;
                    E.EdgeCurve.Neighbors[1] = _Face;
                    Loop.Add(E);
                }
            }

            // Deckel
            _Face = new Face();

            FaceList.Add(_Face);
            //    Face.Surface = PlaneSurfaces[i][j];
            _Face.Bounds  = new Bounds();
            _Face.Surface = new PlaneSurface(UpVertices[0][0].Value, UpVertices[0][1].Value, UpVertices[0][2].Value);
            for (int i = 0; i < _Polygon.Count; i++)
            {
                EdgeLoop Loop = new EdgeLoop();
                _Face.Bounds.Add(Loop);
                for (int j = _Polygon[i].Count - 1; j >= 0; j--)
                {
                    Edge E = new Edge();
                    EdgeList.Add(E);
                    E.EdgeEnd = UpVertices[i][j];
                    if (j + 1 < _Polygon[i].Count)
                    {
                        E.EdgeStart = UpVertices[i][j + 1];
                    }
                    else
                    {
                        E.EdgeStart = UpVertices[i][0];
                    }

                    E.EdgeCurve = UpCurves[i][j];
                    E.SameSense = false;
                    E.EdgeCurve.Neighbors[1] = _Face;
                    Loop.Add(E);
                }
            }
            this.NewParamCurves();
        }