Beispiel #1
0
        public static SimpleGraph <Point3d> LinesToGraph(IEnumerable <Line> Lines, double Tolerance)
        {
            IEnumerator <Line> enumerator = null;

            List <Point3d> point3ds = new List <Point3d>();

            enumerator = Lines.GetEnumerator();
            while (enumerator.MoveNext())
            {
                Line current = enumerator.Current;
                point3ds.Add(current.From);
                point3ds.Add(current.To);
            }


            DuplicateRemover duplicateRemover = new DuplicateRemover(point3ds, Tolerance, 123);

            duplicateRemover.Solve();

            SimpleGraph <Point3d> simpleGraph = new SimpleGraph <Point3d>(duplicateRemover.UniquePoints);
            int num = checked (Lines.Count <Line>() - 1);

            for (int i = 0; i <= num; i = checked (i + 1))
            {
                simpleGraph.Edges.Add(new GraphEdge(checked (i * 2), checked (checked (i * 2) + 1)));
            }
            return(simpleGraph);
        }
Beispiel #2
0
        private SimpleGraph <Point3d> BuildGraph(List <Polyline> Polylines)
        {
            List <Polyline> .Enumerator enumerator = new List <Polyline> .Enumerator();

            SimpleGraph <Point3d> simpleGraph = new SimpleGraph <Point3d>(null);
            PointCloud            pointCloud  = new PointCloud();

            pointCloud.Add(Polylines[0][0]);
            simpleGraph.AddVertex(Polylines[0][0]);
            int num = 0;

            try {
                enumerator = Polylines.GetEnumerator();
                while (enumerator.MoveNext())
                {
                    Polyline  current  = enumerator.Current;
                    GraphEdge count    = new GraphEdge();
                    int       num1     = pointCloud.ClosestPoint(current[0]);
                    Point3d   location = pointCloud[num1].Location;
                    double    num2     = location.DistanceTo(current[0]);
                    count.From = num1;
                    if (num2 > Rhino.RhinoDoc.ActiveDoc.ModelAbsoluteTolerance)
                    {
                        pointCloud.Add(current[0]);
                        simpleGraph.AddVertex(current[0]);
                        count.From = checked (simpleGraph.Count - 1);
                    }
                    num1     = pointCloud.ClosestPoint(current[checked (current.Count - 1)]);
                    count.To = num1;
                    if (pointCloud[num1].Location.DistanceTo(current[checked (current.Count - 1)]) > Rhino.RhinoDoc.ActiveDoc.ModelAbsoluteTolerance)
                    {
                        pointCloud.Add(current[checked (current.Count - 1)]);
                        simpleGraph.AddVertex(current[checked (current.Count - 1)]);
                        count.To = checked (simpleGraph.Count - 1);
                    }
                    count.Orient();
                    this.SrtThick[count] = this.Thickness[num];
                    this.SrtFaces[count] = this.FacesCounts[num];
                    simpleGraph.Edges.Add(count);
                    num = checked (num + 1);
                }
            } finally {
                ((IDisposable)enumerator).Dispose();
            }
            return(simpleGraph);
        }
Beispiel #3
0
        //public PolyMesh BuildMesh(List<Polyline> Polylines, List<int> Strips, List<int> Faces, double Proportion) {
        //    int count;
        //    List<int>.Enumerator enumerator = new List<int>.Enumerator();
        //    HashSet<GraphEdge>.Enumerator enumerator1 = new HashSet<GraphEdge>.Enumerator();
        //    PolyMesh polyMesh = new PolyMesh();
        //    this.Polylines.Clear();
        //    this.Thickness.Clear();
        //    this.FacesCounts.Clear();
        //    this.SrtThick.Clear();
        //    this.SrtFaces.Clear();
        //    this.SrtCircles.Clear();
        //    this.SrtPoints.Clear();
        //    this.SrtEnds.Clear();
        //    this.Proportion = Proportion;
        //    this.Polylines.AddRange(Polylines);
        //    this.FacesCounts.AddRange(Faces);
        //    this.Thickness.AddRange(Strips);
        //    int num = checked(this.FacesCounts.Count - 2);
        //    for (int i = 1; i <= num; i = checked(i + 1)) {
        //        List<int> facesCounts = this.FacesCounts;
        //        List<int> nums = facesCounts;
        //        int num1 = i;
        //        count = num1;
        //        facesCounts[num1] = checked(nums[count] - 6);
        //    }
        //    SimpleGraph<Point3d> simpleGraph = this.BuildGraph(Polylines);
        //    this.WrongVertex = new bool[checked(checked(simpleGraph.Count - 1) + 1)];
        //    List<int>[] connectivityMap = simpleGraph.GetConnectivityMap();
        //    count = checked(this.SrtThick.Count - 1);
        //    for (int j = 0; j <= count; j = checked(j + 1)) {
        //        Circle[] circleArray = new Circle[6];
        //        this.SrtCircles[this.SrtThick.Keys[j]] = circleArray;
        //    }
        //    int count1 = checked(simpleGraph.Count - 1);
        //    for (int k = 0; k <= count1; k = checked(k + 1)) {
        //        List<int> vertex = connectivityMap[k];
        //        if (vertex.Count == 1) {
        //            this.SrtEnds[k] = simpleGraph[k];
        //            this.SrtEnds[vertex[0]] = simpleGraph[vertex[0]];
        //        } else if (vertex.Count == 3) {
        //            List<Point3d> point3ds = new List<Point3d>();
        //            List<Vector3d> vector3ds = new List<Vector3d>();
        //            List<int> nums1 = new List<int>();
        //            try {
        //                enumerator = vertex.GetEnumerator();
        //                while (enumerator.MoveNext()) {
        //                    int current = enumerator.Current;
        //                    Point3d point3d = simpleGraph[current];
        //                    point3d.Transform(Transform.Scale(simpleGraph[k], Proportion));
        //                    vector3ds.Add(simpleGraph[k] - point3d);
        //                    point3ds.Add(point3d);
        //                    GraphEdge graphEdge = new GraphEdge(current, k);
        //                    graphEdge.Orient();
        //                    nums1.Add(this.SrtThick[graphEdge]);
        //                }
        //            } finally {
        //                ((IDisposable)enumerator).Dispose();
        //            }
        //            List<Circle> circles = this.ConstructTangentCircles(point3ds, PointUtil.InscribedCircle(point3ds));
        //            List<Circle> circles1 = this.SecondaryCircles(point3ds, vector3ds, circles);
        //            List<Circle> circles2 = this.TertiaryCircles(point3ds, simpleGraph[k], circles);
        //            int count2 = checked(circles.Count - 1);
        //            for (int l = 0; l <= count2; l = checked(l + 1)) {
        //                GraphEdge item = new GraphEdge(k, vertex[l]);
        //                item.Orient();
        //                if (k != item.From) {
        //                    this.SrtCircles[item][5] = circles[l];
        //                    this.SrtCircles[item][4] = circles1[l];
        //                    this.SrtCircles[item][3] = circles2[l];
        //                } else {
        //                    this.SrtCircles[item][0] = circles[l];
        //                    this.SrtCircles[item][1] = circles1[l];
        //                    this.SrtCircles[item][2] = circles2[l];
        //                }
        //            }
        //            int[] numArray = null;
        //            List<Circle> circles3 = this.OrientPrimary(circles, nums1, ref numArray);
        //            List<int> nums2 = new List<int>();
        //            int length = checked((int)numArray.Length - 1);
        //            for (int m = 0; m <= length; m = checked(m + 1)) {
        //                nums2.Add(nums1[numArray[m]]);
        //                int item1 = vertex[numArray[m]];
        //                GraphEdge graphEdge1 = new GraphEdge(item1, k);
        //                graphEdge1.Orient();
        //                if (item1 != graphEdge1.From) {
        //                    this.SrtCircles[graphEdge1][0] = circles3[m];
        //                } else {
        //                    this.SrtCircles[graphEdge1][5] = circles3[m];
        //                }
        //            }
        //            List<Point3d> point3ds1 = null;
        //            List<Point3d> point3ds2 = null;
        //            List<Point3d> point3ds3 = null;
        //            PolyMesh polyMesh1 = this.MeshConnector(circles3, nums2, ref point3ds1, ref point3ds2, ref point3ds3);
        //            int length1 = checked((int)numArray.Length - 1);
        //            for (int n = 0; n <= length1; n = checked(n + 1)) {
        //                int item2 = vertex[numArray[n]];
        //                GraphEdge array = new GraphEdge(item2, k);
        //                array.Orient();
        //                if (item2 != array.From) {
        //                    switch (n) {
        //                        case 0: {
        //                                this.SrtPoints[new Tuple<int, int, int>(array.From, array.To, 0)] = point3ds3.ToArray();
        //                                break;
        //                            }
        //                        case 1: {
        //                                this.SrtPoints[new Tuple<int, int, int>(array.From, array.To, 0)] = point3ds2.ToArray();
        //                                break;
        //                            }
        //                        case 2: {
        //                                this.SrtPoints[new Tuple<int, int, int>(array.From, array.To, 0)] = point3ds1.ToArray();
        //                                break;
        //                            }
        //                    }
        //                } else {
        //                    switch (n) {
        //                        case 0: {
        //                                this.SrtPoints[new Tuple<int, int, int>(array.From, array.To, 1)] = point3ds3.ToArray();
        //                                break;
        //                            }
        //                        case 1: {
        //                                this.SrtPoints[new Tuple<int, int, int>(array.From, array.To, 1)] = point3ds2.ToArray();
        //                                break;
        //                            }
        //                        case 2: {
        //                                this.SrtPoints[new Tuple<int, int, int>(array.From, array.To, 1)] = point3ds1.ToArray();
        //                                break;
        //                            }
        //                    }
        //                }
        //            }
        //            polyMesh.Append(polyMesh1);
        //        }
        //    }
        //    try {
        //        enumerator1 = simpleGraph.Edges.GetEnumerator();
        //        while (enumerator1.MoveNext()) {
        //            GraphEdge current1 = enumerator1.Current;
        //            if (!(connectivityMap[current1.From].Count == 3 & connectivityMap[current1.To].Count == 3)) {
        //                if (!(connectivityMap[current1.From].Count == 1 & connectivityMap[current1.To].Count == 3 | connectivityMap[current1.From].Count == 3 & connectivityMap[current1.To].Count == 1)) {
        //                    continue;
        //                }
        //                polyMesh.Append(this.BuildEndStrut(current1));
        //            } else {
        //                polyMesh.Append(this.BuildStrut(current1));
        //            }
        //        }
        //    } finally {
        //        ((IDisposable)enumerator1).Dispose();
        //    }
        //    polyMesh.Weld(Rhino.RhinoDoc.ActiveDoc.ModelAbsoluteTolerance, 123);
        //    polyMesh.UnifyFaceNormals();
        //    return polyMesh;
        //}

        public Mesh BuildMesh(List <Polyline> Polylines, List <int> Strips, List <int> Faces, double Proportion)
        {
            int count;

            List <int> .Enumerator enumerator = new List <int> .Enumerator();

            HashSet <GraphEdge> .Enumerator enumerator1 = new HashSet <GraphEdge> .Enumerator();

            Mesh polyMesh = new Mesh();

            this.Polylines.Clear();
            this.Thickness.Clear();
            this.FacesCounts.Clear();
            this.SrtThick.Clear();
            this.SrtFaces.Clear();
            this.SrtCircles.Clear();
            this.SrtPoints.Clear();
            this.SrtEnds.Clear();
            this.Proportion = Proportion;
            this.Polylines.AddRange(Polylines);
            this.FacesCounts.AddRange(Faces);
            this.Thickness.AddRange(Strips);
            int num = checked (this.FacesCounts.Count - 2);

            for (int i = 1; i <= num; i = checked (i + 1))
            {
                List <int> facesCounts = this.FacesCounts;
                List <int> nums        = facesCounts;
                int        num1        = i;
                count             = num1;
                facesCounts[num1] = checked (nums[count] - 6);
            }
            SimpleGraph <Point3d> simpleGraph = this.BuildGraph(Polylines);

            this.WrongVertex = new bool[checked (checked (simpleGraph.Count - 1) + 1)];
            List <int>[] connectivityMap = simpleGraph.GetConnectivityMap();
            count = checked (this.SrtThick.Count - 1);
            for (int j = 0; j <= count; j = checked (j + 1))
            {
                Circle[] circleArray = new Circle[6];
                this.SrtCircles[this.SrtThick.Keys[j]] = circleArray;
            }
            int count1 = checked (simpleGraph.Count - 1);

            for (int k = 0; k <= count1; k = checked (k + 1))
            {
                List <int> vertex = connectivityMap[k];
                if (vertex.Count == 1)
                {
                    this.SrtEnds[k]         = simpleGraph[k];
                    this.SrtEnds[vertex[0]] = simpleGraph[vertex[0]];
                }
                else if (vertex.Count == 3)
                {
                    List <Point3d>  point3ds  = new List <Point3d>();
                    List <Vector3d> vector3ds = new List <Vector3d>();
                    List <int>      nums1     = new List <int>();
                    try {
                        enumerator = vertex.GetEnumerator();
                        while (enumerator.MoveNext())
                        {
                            int     current = enumerator.Current;
                            Point3d point3d = simpleGraph[current];
                            point3d.Transform(Transform.Scale(simpleGraph[k], Proportion));
                            vector3ds.Add(simpleGraph[k] - point3d);
                            point3ds.Add(point3d);
                            GraphEdge graphEdge = new GraphEdge(current, k);
                            graphEdge.Orient();
                            nums1.Add(this.SrtThick[graphEdge]);
                        }
                    } finally {
                        ((IDisposable)enumerator).Dispose();
                    }
                    List <Circle> circles  = this.ConstructTangentCircles(point3ds, PointUtil.InscribedCircle(point3ds));
                    List <Circle> circles1 = this.SecondaryCircles(point3ds, vector3ds, circles);
                    List <Circle> circles2 = this.TertiaryCircles(point3ds, simpleGraph[k], circles);
                    int           count2   = checked (circles.Count - 1);
                    for (int l = 0; l <= count2; l = checked (l + 1))
                    {
                        GraphEdge item = new GraphEdge(k, vertex[l]);
                        item.Orient();
                        if (k != item.From)
                        {
                            this.SrtCircles[item][5] = circles[l];
                            this.SrtCircles[item][4] = circles1[l];
                            this.SrtCircles[item][3] = circles2[l];
                        }
                        else
                        {
                            this.SrtCircles[item][0] = circles[l];
                            this.SrtCircles[item][1] = circles1[l];
                            this.SrtCircles[item][2] = circles2[l];
                        }
                    }
                    int[]         numArray = null;
                    List <Circle> circles3 = this.OrientPrimary(circles, nums1, ref numArray);
                    List <int>    nums2    = new List <int>();
                    int           length   = checked ((int)numArray.Length - 1);
                    for (int m = 0; m <= length; m = checked (m + 1))
                    {
                        nums2.Add(nums1[numArray[m]]);
                        int       item1      = vertex[numArray[m]];
                        GraphEdge graphEdge1 = new GraphEdge(item1, k);
                        graphEdge1.Orient();
                        if (item1 != graphEdge1.From)
                        {
                            this.SrtCircles[graphEdge1][0] = circles3[m];
                        }
                        else
                        {
                            this.SrtCircles[graphEdge1][5] = circles3[m];
                        }
                    }
                    List <Point3d> point3ds1 = null;
                    List <Point3d> point3ds2 = null;
                    List <Point3d> point3ds3 = null;
                    Mesh           polyMesh1 = this.MeshConnector(circles3, nums2, ref point3ds1, ref point3ds2, ref point3ds3);
                    int            length1   = checked ((int)numArray.Length - 1);
                    for (int n = 0; n <= length1; n = checked (n + 1))
                    {
                        int       item2 = vertex[numArray[n]];
                        GraphEdge array = new GraphEdge(item2, k);
                        array.Orient();
                        if (item2 != array.From)
                        {
                            switch (n)
                            {
                            case 0: {
                                this.SrtPoints[new Tuple <int, int, int>(array.From, array.To, 0)] = point3ds3.ToArray();
                                break;
                            }

                            case 1: {
                                this.SrtPoints[new Tuple <int, int, int>(array.From, array.To, 0)] = point3ds2.ToArray();
                                break;
                            }

                            case 2: {
                                this.SrtPoints[new Tuple <int, int, int>(array.From, array.To, 0)] = point3ds1.ToArray();
                                break;
                            }
                            }
                        }
                        else
                        {
                            switch (n)
                            {
                            case 0: {
                                this.SrtPoints[new Tuple <int, int, int>(array.From, array.To, 1)] = point3ds3.ToArray();
                                break;
                            }

                            case 1: {
                                this.SrtPoints[new Tuple <int, int, int>(array.From, array.To, 1)] = point3ds2.ToArray();
                                break;
                            }

                            case 2: {
                                this.SrtPoints[new Tuple <int, int, int>(array.From, array.To, 1)] = point3ds1.ToArray();
                                break;
                            }
                            }
                        }
                    }
                    polyMesh.Append(polyMesh1);
                }
            }
            try {
                enumerator1 = simpleGraph.Edges.GetEnumerator();
                while (enumerator1.MoveNext())
                {
                    GraphEdge current1 = enumerator1.Current;
                    if (!(connectivityMap[current1.From].Count == 3 & connectivityMap[current1.To].Count == 3))
                    {
                        if (!(connectivityMap[current1.From].Count == 1 & connectivityMap[current1.To].Count == 3 | connectivityMap[current1.From].Count == 3 & connectivityMap[current1.To].Count == 1))
                        {
                            continue;
                        }
                        polyMesh.Append(this.BuildEndStrut(current1));
                    }
                    else
                    {
                        polyMesh.Append(this.BuildStrut(current1));
                    }
                }
            } finally {
                ((IDisposable)enumerator1).Dispose();
            }

            polyMesh.Clean();
            //polyMesh.Weld(Rhino.RhinoDoc.ActiveDoc.ModelAbsoluteTolerance, 123);
            //polyMesh.UnifyFaceNormals();
            return(polyMesh);
        }