Пример #1
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;
        }
Пример #2
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;
            }
        }
Пример #3
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();
        }
Пример #4
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();
            //}
        }
Пример #5
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())
            //{
            //}
        }
Пример #6
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();
        }
Пример #7
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();
        }