Exemplo n.º 1
0
        bool Check()
        {
            int FC = FaceList.Count;
            int KC = EdgeCurveList.Count;
            int EC = VertexList.Count;
            int CT = EC - KC + FC - 2; // Euler

            if (CT == 0)
            {
                int ED = EdgeList.Count;
                if (ED == 2 * KC)
                {  /* Ok*/
                }
                else
                {//   return false;
                }
            }
            else
            {
                //  return false;
                for (int i = 0; i < EdgeCurveList.Count; i++)
                {
                    Edge[] Edges = EdgeCurveList[i].Tag as Edge[];
                    if (Edges != null)
                    {
                        if ((Edges[0] == null) || (Edges[1] == null))
                        {
                        }
                        else
                        {
                            if (EdgeList.IndexOf(Edges[0]) == -1)
                            {
                            }

                            if (EdgeList.IndexOf(Edges[1]) == -1)
                            {
                            }
                        }
                    }

                    if (EdgeCurveList[i].A.dist(EdgeCurveList[i].B) < 0.0001)
                    {
                    }
                }
            }
            if (!CheckEdges())
            {
            }
            ;                      // return false;
            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];
                        int  OutLoop = -1;

                        if ((E.SameSense) && (
                                (E.EdgeCurve.A.dist(E.EdgeStart.Value) > 0.0001) ||
                                (E.EdgeCurve.B.dist(E.EdgeEnd.Value) > 0.0001)))
                        {
                            return(false);
                        }
                        if ((!E.SameSense) && (
                                (E.EdgeCurve.B.dist(E.EdgeStart.Value) > 0.0001) ||
                                (E.EdgeCurve.A.dist(E.EdgeEnd.Value) > 0.0001)))
                        {
                            return(false);
                        }
                        Face FF = null;
                        if (E.EdgeCurve.Neighbors[0] == null)
                        {
                            return(false);
                        }



                        if (E.EdgeCurve is Line3D)
                        {
                            Line3D Curve3d = E.EdgeCurve as Line3D;
                            xyz    _A      = F.Surface.Base.Relativ(Curve3d.A);
                            xyz    _B      = F.Surface.Base.Relativ(Curve3d.B);
                            if (System.Math.Abs(_A.z) > 0.001)
                            {
                                return(false);
                            }
                            double g  = F.Surface.Base.BaseX.length();
                            double h  = F.Surface.Base.BaseY.length();
                            xyz    AA = F.Surface.Base.Absolut(_A);
                            xyz    BB = F.Surface.Base.Absolut(_B);
                            if (AA.dist(Curve3d.A) > 0.001)
                            {
                                return(false);
                            }
                        }
                        if (E.EdgeCurve.Neighbors[0] == E.EdgeCurve.Neighbors[1])
                        {
                            return(false);
                        }
                        if (!FaceList.Contains(E.EdgeCurve.Neighbors[0]))
                        {
                        }
                        if (!FaceList.Contains(E.EdgeCurve.Neighbors[1]))
                        {
                            return(false);
                        }


                        double d = Face.GetDualEdge(F, j, k + 0.01, ref OutLoop, ref FF);
                    }
                }
            }
            return(true);
        }
Exemplo n.º 2
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();
        }
Exemplo n.º 3
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();
        }
Exemplo n.º 4
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())
            //{
            //}
        }
Exemplo n.º 5
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();
        }