コード例 #1
0
        public Shell GetInsidePart()
        {
            closedBorder.Flatten();
            if (!closedBorder.IsClosed)
            {
                Line l = Line.Construct();
                l.SetTwoPoints(closedBorder.EndPoint, closedBorder.StartPoint);
                closedBorder.Add(l);
            }
            vertexToFace = new Face[closedBorder.CurveCount];
            for (int i = 0; i < closedBorder.CurveCount; i++)
            {
                Face fc = FindClosestFace(closedBorder.Curve(i).StartPoint);
                if (fc == null)
                {
                    throw new SplitShellWithCurvesException();
                }
                vertexToFace[i] = fc;
            }
            all2DCurves  = new Dictionary <Face, List <ICurve2D> >();
            splitedEdges = new Dictionary <Edge, List <double> >();
            for (int i = 0; i < vertexToFace.Length; i++)
            {
                InsertCurve(i);
            }
            // jetzt die Faces beschneiden und eine neue Shell bauen
            Vertex[] vertices = shell.Vertices;
            outsideVertices = new Set <Vertex>();
            for (int i = 0; i < vertices.Length; i++)
            {   // wenn der Vertex eine Außenkante hat, dann gilt er als außenliegend
                Edge[] vedges = vertices[i].Edges;
                for (int j = 0; j < vedges.Length; j++)
                {
                    if (vedges[j].SecondaryFace == null)
                    {
                        FollowVertex(vertices[j]);
                    }
                }
            }
#if DEBUG
            DebuggerContainer dc = new DebuggerContainer();
            foreach (Vertex vtx in outsideVertices)
            {
                Point pnt = Point.Construct();
                pnt.Location = vtx.Position;
                pnt.Symbol   = PointSymbol.Circle;
                dc.Add(pnt, vtx.GetHashCode());
            }
#endif
            // alle Faces, die aufgesplitted werden müssen:
            Set <Face> splittedFaces = new Set <Face>();
            foreach (Edge edge in splitedEdges.Keys)
            {
                splittedFaces.Add(edge.PrimaryFace);
                if (edge.SecondaryFace != null)
                {
                    splittedFaces.Add(edge.SecondaryFace);
                }
            }
            resultingFaces = new List <Face>();
            for (int i = 0; i < shell.Faces.Length; i++)
            {
                Face face = shell.Faces[i];
                if (splittedFaces.Contains(face))
                {
                    AddSplittedFace(face);
                }
                else
                {
                    if (!outsideVertices.Contains(face.Vertices[0]))
                    {
                        resultingFaces.Add(face.Clone() as Face);
                    }
                }
            }
            GeoObjectList res = Make3D.SewFacesAndShells(new GeoObjectList(resultingFaces.ToArray()));
            if (res.Count == 1)
            {
                return(res[0] as Shell);
            }
            return(null);
        }