예제 #1
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            Mesh mesh = new Mesh();

            DA.GetData(0, ref mesh);
            int iteration = DA.Iteration;

            uint[][]     fId        = mesh.GetFacesInNGons();
            Polyline[][] fPolylines = mesh.GetFacePolylinesInNgons(fId);

            List <Polyline> display = new List <Polyline>();

            foreach (var d in fPolylines)
            {
                foreach (var dd in d)
                {
                    if (dd != null && dd.IsValid)
                    {
                        display.Add(dd);
                    }
                }
            }


            this.PreparePreview(mesh, DA.Iteration, display, false, null);
            var dtPlines = GrasshopperUtil.JaggedArraysToTree(fPolylines, iteration);

            DA.SetDataTree(0, dtPlines);
            DA.SetDataTree(1, GrasshopperUtil.JaggedArraysToTree(fId, iteration));
        }
예제 #2
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            Mesh mesh  = new Mesh();
            Mesh mesh_ = new Mesh();

            DA.GetData(0, ref mesh);

            double scale = 1;

            DA.GetData(1, ref scale);

            //int t = 0;
            //DA.GetData(2, ref t);

            Polyline[][] pairplines = null;
            var          m          = mesh.ProjectPairsMesh(scale, ref pairplines);

            foreach (var mm in m)
            {
                mm.Clean();
                mesh_.Append(mm);
            }
            this.PreparePreview(mesh_, DA.Iteration);


            DA.SetDataList(0, m);
            DA.SetDataTree(1, GrasshopperUtil.JaggedArraysToTree(pairplines, 0));
        }
예제 #3
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            List <Mesh> mesh = new List <Mesh>();

            if (DA.GetDataList(0, mesh))
            {
                List <int>[] mc = MeshUtilSimple.MeshCollisions(mesh);
                DA.SetDataTree(0, GrasshopperUtil.ArrayOfListsToTree(mc));

                //Next check overlapping faces only if ngons exists

                List <Polyline[]>[] mcPlines = new List <Polyline[]> [mc.Length];

                for (int i = 0; i < mc.Length; i++)
                {
                    mcPlines[i] = new List <Polyline[]>();

                    for (int j = 0; j < mc[i].Count; j++)
                    {
                        //Do it with ngons
                        MeshUtil.GetOverlap(mesh[i], mesh[mc[i][j]], 0.1);
                    }
                }
            }//if
        }
예제 #4
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            Mesh mesh = new Mesh();

            DA.GetData(0, ref mesh);
            int iteration = DA.Iteration;

            uint[][] v  = mesh.GetNGonsBoundaries();
            int[][]  tv = mesh.GetNGonsTopoBoundaries();



            var pt = mesh.GetNGonsBoundariesPoint3F(v);

            List <Point3d> points    = new List <Point3d>();
            List <Line[]>  lineArray = new List <Line[]>();

            foreach (var p in pt)
            {
                Point3d center = new Point3d();
                foreach (var pp in p)
                {
                    center += pp;
                    points.Add(pp);
                }
                center /= p.Length;

                Point3d[] p_Copy = new Point3d[p.Length];
                int       i      = 0;
                foreach (var pp in p)
                {
                    Point3d pp_Copy = pp;
                    pp_Copy.Transform(Rhino.Geometry.Transform.Scale(center, 0.95));
                    p_Copy[i++] = pp_Copy;
                }
                lineArray.Add(p_Copy.ToLineArray(true));
            }

            this.PreparePreview(mesh, iteration, null, false, points, null, 255, 0, 0, lineArray);



            DA.SetDataTree(0, GrasshopperUtil.JaggedArraysToTree(pt, iteration));
            // DA.SetDataTree(0, Util.JaggedArraysToTree(MeshUtil.GetNGonsTopoBoundariesPoint3F(mesh, tv), iteration));
            DA.SetDataTree(1, GrasshopperUtil.JaggedArraysToTree(v, iteration));
            DA.SetDataTree(2, GrasshopperUtil.JaggedArraysToTree(tv, iteration));
        }
예제 #5
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            Mesh mesh = new Mesh();

            DA.GetData(0, ref mesh);
            int iteration = DA.Iteration;



            //Vertex array as number of ngons
            int n = mesh.Ngons.Count;

            int[] nodes = Enumerable.Range(0, n).ToArray();

            //Get face adjacency
            List <int>[] adj = mesh.GetNgonFaceAdjacencyOrdered();

            //Edges start and end point
            List <int> edges0 = new List <int>();
            List <int> edges1 = new List <int>();

            for (int i = 0; i < adj.Length; i++)
            {
                edges0.AddRange(adj[i]);
                edges1.AddRange(Enumerable.Repeat(i, adj[i].Count));
            }

            //Output
            //V = nodes;
            //E0 = edges0;
            //E1 = edges1;

            DataTree <int> dt0 = new DataTree <int>();
            DataTree <int> dt1 = new DataTree <int>();
            DataTree <int> dt2 = new DataTree <int>();

            dt0.AddRange(nodes, new Grasshopper.Kernel.Data.GH_Path(iteration));
            dt1.AddRange(edges0, new Grasshopper.Kernel.Data.GH_Path(iteration));
            dt2.AddRange(edges1, new Grasshopper.Kernel.Data.GH_Path(iteration));

            DA.SetDataTree(0, GrasshopperUtil.ArrayOfListsToTree(adj, iteration));
            DA.SetDataTree(1, dt0);
            DA.SetDataTree(2, dt1);
            DA.SetDataTree(3, dt2);
        }
예제 #6
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            Mesh   mesh  = new Mesh();
            double d     = 1;
            double step  = 0.25;
            double scale = 0.9;
            var    additionalPolylines = new GH_Structure <GH_Curve>();

            if (DA.GetData(0, ref mesh))
            {
                DA.GetData(1, ref d);
                DA.GetData(2, ref step);
                DA.GetData(3, ref scale);
                DA.GetDataTree(4, out additionalPolylines);

                var additionalPolylinesCopy = new GH_Structure <GH_Curve>(additionalPolylines, false);

                bool flag = true;
                if (additionalPolylines.Branches.Count != 2)
                {
                    flag = false;
                }
                else
                {
                    if (additionalPolylines[0].Count != mesh.Ngons.Count || additionalPolylines[1].Count != mesh.Ngons.Count)
                    {
                        flag = false;
                    }
                }
                if (!flag)
                {
                    var plines = Joinery.Miter(mesh, d, step, scale, ref additionalPolylinesCopy);

                    DA.SetDataTree(1, GrasshopperUtil.ListOfListsToTree(plines, DA.Iteration));
                    DA.SetDataTree(2, additionalPolylinesCopy);
                }
                else
                {
                    //public static List<List<Polyline>> Miter(Mesh M,  double D,double JointStep, double scale, ref GH_Structure<GH_Curve> additionalPlines)
                    var plines = Joinery.Miter(mesh, d, step, scale, additionalPolylinesCopy);
                    DA.SetDataTree(2, GrasshopperUtil.ListOfListsToTree(plines, DA.Iteration));
                    //DA.SetDataTree(2, additionalPolylinesCopy);
                }
            }
        }
예제 #7
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            Mesh mesh = new Mesh();

            DA.GetData(0, ref mesh);
            int iteration = DA.Iteration;

            HashSet <int> allNGonTvAll = mesh.GetAllNGonsTopoVertices();

            int[][]       nGonTV      = mesh.GetNGonsTopoBoundaries();
            HashSet <int> allNGonEAll = mesh.GetAllNGonEdges(nGonTV);

            int[][]  connectedE     = mesh.GetConnectedNGonEdgesToNGonTopologyVertices(allNGonTvAll, allNGonEAll);
            Line[][] connectedLines = mesh.GetConnectedNGonLinesToNGonTopologyVertices(connectedE);

            DA.SetDataTree(0, GrasshopperUtil.JaggedArraysToTree(connectedLines, iteration));
            DA.SetDataTree(1, GrasshopperUtil.JaggedArraysToTree(connectedE, iteration));
        }
예제 #8
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            Mesh mesh = new Mesh();

            DA.GetData(0, ref mesh);
            int iteration = DA.Iteration;

            //Inputs
            int[][]       tv    = mesh.GetNGonsTopoBoundaries();
            HashSet <int> tvAll = mesh.GetAllNGonsTopoVertices();
            HashSet <int> e     = mesh.GetAllNGonEdges(tv);

            int[] allEArray = e.ToArray();
            int[] allvArray = tvAll.ToArray();

            //Outputs
            Point3f[]        allVPt = mesh.GetAllNGonsTopoVerticesPoint3F(tvAll);
            List <int>[]     conV   = mesh.GetConnectedNgonVertices(allEArray, allvArray);
            List <Point3d>[] conVP  = mesh.GetConnectedNgonPoints(conV);

            List <Line> lines = new List <Line>();

            for (int i = 0; i < conVP.Length; i++)
            {
                foreach (Point3d j in conVP[i])
                {
                    Point3d p = new Point3d(allVPt[i]);
                    Line    l = new Line(p, j);
                    l.Transform(Rhino.Geometry.Transform.Scale(p, 0.25));
                    lines.Add(l);
                }
            }



            this.PreparePreview(mesh, DA.Iteration, null, false, null, lines);


            DA.SetDataTree(0, new DataTree <Point3f>(allVPt, new GH_Path(iteration)));
            DA.SetDataTree(1, GrasshopperUtil.ArrayOfListsToTree(conVP, iteration));
            DA.SetDataTree(2, new DataTree <int>(tvAll, new GH_Path(iteration)));
            DA.SetDataTree(3, GrasshopperUtil.ArrayOfListsToTree(conV, iteration));
        }
예제 #9
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            Mesh mesh = new Mesh();

            DA.GetData(0, ref mesh);
            double DistanceDivision = 10000;

            DA.GetData(1, ref DistanceDivision);
            int iteration = DA.Iteration;


            int[][]       tv         = mesh.GetNGonsTopoBoundaries();
            int[][]       fe         = mesh.GetNGonFacesEdges(tv);
            Point3d[][][] edgePoints = mesh.GetNGonFacesEdgesLinesPoints(fe, DistanceDivision);
            // var l = mesh.GetNGonFacesEdgesLines(fe);

            // DataTree<int> dt2 = new DataTree<int>();
            // HashSet<int> allE = mesh.GetAllNGonEdges(tv);
            // int[] allEArray = allE.ToArray();
            //int[][] ef = mesh.GetNgonsConnectedToNGonsEdges(allE, true);

            // for(int i = 0; i < mesh.Ngons.Count; i++) {
            //     for(int j = 0; j < fe[i].Length; j++) {
            //         int elocal = Array.IndexOf(allEArray, fe[i][j]);
            //         int neiF = (ef[elocal][0] == i) ? ef[elocal][1] : ef[elocal][0];
            //         dt2.Add(neiF,new Grasshopper.Kernel.Data.GH_Path(i,DA.Iteration));
            //     }
            // }

            // List< Line > ld = new List<Line>();
            // foreach (var ll in l)
            //     ld.AddRange(ll);



            // DA.SetDataTree(0, GrasshopperUtil.JaggedArraysToTree(l, iteration));
            // DA.SetDataTree(1, GrasshopperUtil.JaggedArraysToTree(fe, iteration));
            // DA.SetDataTree(2, dt2);
            var pts = GrasshopperUtil.TripleArraysToTree(edgePoints, iteration);

            DA.SetDataTree(0, pts);
            this.PreparePreview(mesh, DA.Iteration, null, false, pts.AllData());
        }
예제 #10
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            Mesh m = new Mesh();

            DA.GetData(0, ref m);

            double dist = DA.Fetch <double>("Offset");
            bool   flip = DA.Fetch <bool>("Flip");

            if (dist != 0)
            {
                m = m.FaceFaceOffset(dist);
                //Rhino.RhinoDoc.ActiveDoc.Objects.AddMesh(m);
            }

            Mesh M = NGonsCore.MeshCreate.MeshFromPolylines(m.GetFacePolylinesArray(), 0.01);

            if (flip)
            {
                M.Flip(true, true, true);
            }
            DA.SetData(4, M);

            try
            {
                MeshProps mp = M._Planes();



                DA.SetData(0, mp);
                DA.SetDataTree(1, GrasshopperUtil.IE(mp.fPl, -1));
                DA.SetDataTree(2, GrasshopperUtil.IE2(mp.fePl));
                // DA.SetDataTree(3, GrasshopperUtil.IE2(mp.fePl90));
                DA.SetDataTree(3, GrasshopperUtil.IE(mp.ePl));
                //DA.SetDataTree(5, GrasshopperUtil.IE(mp.ePl90));
            }
            catch (Exception e)
            {
                Rhino.RhinoApp.WriteLine(e.ToString());
            }
        }
예제 #11
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            Mesh m = new Mesh();

            DA.GetData(0, ref m);
            int i = 0;

            DA.GetData(1, ref i);
            int iterations = 0;

            DA.GetData(2, ref iterations);

            if (m.IsValid)
            {
                List <List <int> > nakedVertices  = m.GetNakedVerticesID(iterations);
                List <Polyline>    nakedPolylines = m.GetNakedPolylines(nakedVertices);
                Mesh mesh = m.DuplicateMesh();


                if (nakedVertices.Count != 0)
                {
                    int check = mesh.Ngons.AddNgon(MeshNgon.Create(nakedVertices[i.Wrap(nakedVertices.Count)], Enumerable.Range(0, m.Faces.Count).ToList()));
                    PreparePreview(mesh, DA.Iteration, nakedPolylines);
                    DA.SetData(0, mesh);
                    DA.SetDataTree(1, GrasshopperUtil.IE2(nakedVertices, DA.Iteration));
                    DA.SetDataTree(2, GrasshopperUtil.IE(nakedPolylines, DA.Iteration));
                }
                else
                {
                    DA.SetData(0, m);
                    DA.SetDataTree(1, new Grasshopper.DataTree <int>());
                    DA.SetDataTree(2, new Grasshopper.DataTree <Polyline>());
                }
            }
            else
            {
                DA.SetData(0, m);
                DA.SetDataTree(1, new Grasshopper.DataTree <int>());
                DA.SetDataTree(2, new Grasshopper.DataTree <Polyline>());
            }
        }
예제 #12
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            Mesh   mesh = new Mesh();
            double d    = 1;
            bool   f    = false;
            bool   n    = false;
            bool   c    = false;

            if (DA.GetData(0, ref mesh))
            {
                DA.GetData(1, ref d);
                DA.GetData(2, ref f);
                DA.GetData(3, ref n);
                DA.GetData(4, ref c);

                var meshes = new List <Mesh>();
                var plines = mesh.GetFlaps(d, f, n, c, ref meshes);
                DA.SetDataList(0, meshes);
                DA.SetDataTree(1, GrasshopperUtil.ListOfListsToTree(plines, DA.Iteration));
            }
        }
예제 #13
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            Mesh mesh = new Mesh();

            DA.GetData(0, ref mesh);

            double dist = 0.5;

            DA.GetData(1, ref dist);

            var o = mesh.OffsetNgon(dist);


            Polyline[] polylines = mesh.OffsetNgonAndMerge(dist);
            this.PreparePreview(mesh, DA.Iteration, polylines.ToList(), false);

            DA.SetDataTree(0, GrasshopperUtil.JaggedArraysToTree(o.Item1, 0));

            DA.SetDataList(1, o.Item2);
            DA.SetDataList(2, polylines);
        }
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            Mesh mesh = new Mesh();

            DA.GetData(0, ref mesh);
            bool flag = true;

            DA.GetData(1, ref flag);

            int iteration = DA.Iteration;

            HashSet <int> tvAll = mesh.GetAllNGonsTopoVertices();

            int[][] NGons = mesh.GetNGonsConnectedToNGonTopologyVertices(tvAll, flag);


            bool[] nakedNGonVertices = mesh.GetNakedNGonTopologyPointStatus(tvAll);



            DA.SetDataTree(0, GrasshopperUtil.JaggedArraysToTree(NGons, iteration));
            DA.SetDataList(1, nakedNGonVertices);
        }
예제 #15
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            Mesh mesh = new Mesh();

            DA.GetData(0, ref mesh);
            double size = 10;

            DA.GetData(1, ref size);

            double textScale = 0.75;

            DA.GetData(2, ref textScale);
            int iteration = DA.Iteration;

            bbox.Union(mesh.GetBoundingBox(false));


            int[][]        tv   = mesh.GetNGonsTopoBoundaries();
            int[][]        fe   = mesh.GetNGonFacesEdges(tv);
            var            l    = mesh.GetNGonFacesEdgesLines(fe);
            DataTree <int> dt2  = new DataTree <int>();
            HashSet <int>  allE = mesh.GetAllNGonEdges(tv);

            int[]   allEArray = allE.ToArray();
            int[][] ef        = mesh.GetNgonsConnectedToNGonsEdges(allE, true);

            for (int i = 0; i < mesh.Ngons.Count; i++)
            {
                for (int j = 0; j < fe[i].Length; j++)
                {
                    int elocal = Array.IndexOf(allEArray, fe[i][j]);
                    int neiF   = (ef[elocal][0] == i) ? ef[elocal][1] : ef[elocal][0];
                    dt2.Add(neiF, new Grasshopper.Kernel.Data.GH_Path(i, DA.Iteration));
                }
            }

            List <Line> ld = new List <Line>();

            foreach (var ll in l)
            {
                ld.AddRange(ll);
            }

            //this.PreparePreview(mesh, DA.Iteration, null, false,null,ld);


            Plane[] planes = mesh.GetNgonPlanes();

            for (int i = 0; i < planes.Length; i++)
            {
                if (faces)
                {
                    this.texts.Add(new Rhino.Display.Text3d("F" + i.ToString(), planes[i], size));
                }
            }

            for (int i = 0; i < planes.Length; i++)
            {
                for (int j = 0; j < fe[i].Length; j++)
                {
                    Point3d p = l[i][j].PointAt(0.5);
                    p.Transform(Rhino.Geometry.Transform.Scale(planes[i].Origin, textScale));
                    Plane edgePlane = new Plane(p, l[i][j].Direction, Vector3d.CrossProduct(planes[i].ZAxis, l[i][j].Direction));
                    if (edgesE)
                    {
                        this.texts.Add(new Rhino.Display.Text3d("E" + fe[i][j].ToString(), edgePlane, size * 0.75));
                    }
                    if (edgesF)
                    {
                        this.texts.Add(new Rhino.Display.Text3d("F" + dt2.Branch(i)[j].ToString(), edgePlane, size * 0.75));
                    }
                }
            }


            DA.SetDataTree(0, GrasshopperUtil.JaggedArraysToTree(l, iteration));
            DA.SetDataTree(1, GrasshopperUtil.JaggedArraysToTree(fe, iteration));
            DA.SetDataTree(2, dt2);
        }
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            //Input
            Mesh mesh = new Mesh();

            DA.GetData(0, ref mesh);
            int iteration = DA.Iteration;

            GH_Structure <GH_Integer> pairs = new GH_Structure <GH_Integer>();

            DA.GetDataTree(1, out pairs);

            double scale = 0.9;

            DA.GetData(2, ref scale);

            //Solution

            int[][] p = new int[pairs.PathCount][];

            //Grasshopper datatree to int[] {a,b}
            for (int i = 0; i < pairs.PathCount; i++)
            {
                p[i] = (new int[] { pairs[i][0].Value, pairs[i][1].Value });
            }


            var edges = mesh.FindMeshEdgeByNGonPair(p);

            //Offset all lines by dist
            int[][]  NGFaceEdgesID = edges.Item4;
            Line[][] NGFacesEdges  = new Line[edges.Item4.Length][];

            //Get face centers
            Point3d[] centers = mesh.GetNGonCenters();

            for (int i = 0; i < edges.Item4.Length; i++)
            {
                NGFacesEdges[i] = new Line[edges.Item4[i].Length];
                for (int j = 0; j < edges.Item4[i].Length; j++)
                {
                    Line l = mesh.TopologyEdges.EdgeLine(NGFaceEdgesID[i][j]);
                    l.Transform(Rhino.Geometry.Transform.Scale(centers[i], scale));
                    NGFacesEdges[i][j] = l;

                    if (edges.Item6.ContainsKey(NGFaceEdgesID[i][j]))
                    {
                        edges.Item5[NGFaceEdgesID[i][j]].Add(l.From);
                        edges.Item5[NGFaceEdgesID[i][j]].Add(l.To);
                    }
                }
            }



            //Draw line between face centers
            //pairs gives a and b face
            //item1 gives flag
            //item3 gives edges id

            //Create dictionary with KEY - edge id VALUE - flag
            //Then dictionary with KEY - edge id VALUE - end points


            Polyline[] plines = new Polyline[edges.Item6.Count];
            int        id     = 0;

            foreach (var i in edges.Item5)
            {
                plines[id] = new Polyline(new Point3d[] { i.Value[0], i.Value[1], i.Value[3], i.Value[2], i.Value[0] });
                id++;
            }
            //Output

            DA.SetDataList(0, edges.Item2);
            DA.SetDataList(1, edges.Item3);
            DA.SetDataList(2, edges.Item1);
            DA.SetDataTree(3, GrasshopperUtil.JaggedArraysToTree(NGFacesEdges, 0));
            DA.SetDataList(4, plines);
        }
예제 #17
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            Mesh        mesh          = DA.Fetch <Mesh>("Mesh");
            string      v             = DA.Fetch <string>("Start");
            List <int>  o             = DA.FetchList <int>("Sequence");
            Curve       sequenceCrv   = DA.Fetch <Curve>("SequenceCrv");
            List <Line> customVectors = DA.FetchList <Line>("CustomVectors");
            double      angleTol      = DA.Fetch <double>("Angle");



            v = Math.Min(Convert.ToInt32(v), mesh.Ngons.Count - 1).ToString();



            if (mesh.Ngons.Count == o.Count)
            {
                mesh         = mesh.ReoderMeshNgons(o);
                base.Message = "Sequence";
            }
            else if (sequenceCrv != null)
            {
                if (sequenceCrv.IsValid)
                {
                    mesh = mesh.ReoderMeshNgons(sequenceCrv);
                    List <int> order = Enumerable.Range(0, mesh.Ngons.Count).ToList();
                    base.Message = "Sequence Curve";
                }
            }
            else
            {
                var        ve    = NGonsCore.Graphs.UndirectedGraphBfsRhino.MeshBFS(mesh, v);
                List <int> order = ve.Item1[0];
                mesh         = mesh.ReoderMeshNgons(ve.Item1[0]);
                base.Message = "BFS";
                DA.SetDataTree(0, GrasshopperUtil.IE2(ve.Item1));
                DA.SetDataTree(1, GrasshopperUtil.IE3(ve.Item2));
            }

            DA.SetData(4, mesh);


            List <int> order_ = Enumerable.Range(0, mesh.Ngons.Count).ToList();

            DataTree <int> vertices_ = new DataTree <int>(order_);
            DataTree <int> edges_    = new DataTree <int>();

            for (int i = 0; i < order_.Count - 1; i++)
            {
                edges_.Add(order_[i], new GH_Path(i));
                edges_.Add(order_[i] + 1, new GH_Path(i));
            }


            int S = mesh.Ngons.Count;//stop
            //Insertion vectors
            DataTree <int> N = SequenceNeighbours(mesh, order_, S);

            //FN = N;
            //O_ = O;
            //Edge Vectors
            int[][]                 tv     = mesh.GetNGonsTopoBoundaries();
            int[][]                 fe     = mesh.GetNGonFacesEdges(tv);
            HashSet <int>           e      = mesh.GetAllNGonEdges(tv);
            Dictionary <int, int[]> efDict = mesh.GetFE(e, false);

            Polyline[] outlines = mesh.GetPolylines();



            //Dictionary<int, Vector3d> edgeVectors = new Dictionary<int, Vector3d> ();
            DataTree <Vector3d> edgeVectors = new DataTree <Vector3d>();
            List <Vector3d>     faceVectors = new List <Vector3d>();
            Dictionary <int, List <GH_Path> > faceEdgeID = new Dictionary <int, List <GH_Path> >();


            for (int i = 0; (i < S && i < mesh.Ngons.Count); i++)
            {
                /////////////
                // Properties
                /////////////
                //Current path and face
                GH_Path p = new GH_Path(i);
                int     f = order_[i];//O[i];
                if (!N.PathExists(p))
                {
                    continue;                                        //If no connectio nskip
                }
                HashSet <int> fadj = new HashSet <int>(N.Branch(p)); //adjacency list


                /////////////
                // Solution
                /////////////
                //Iterate mesh edges
                //Get connected faces
                //Check if they are in adjacency list
                //The order thoses ids

                List <int> NotOrderedEdges = new List <int>();
                for (int j = 0; j < fe[f].Length; j++)
                {
                    int[] facePair = efDict[fe[f][j]];//get face pair
                    if (facePair.Length == 1)
                    {
                        continue;                      //if naked skip
                    }
                    if (fadj.Contains(facePair[0]) || fadj.Contains(facePair[1]))
                    {
                        NotOrderedEdges.Add(j);                                                          //if edge face are in fadj
                    }
                }

                List <int> orderedEdges = SortIntegers(NotOrderedEdges, fe[f].Length);


                //Collect lines for Insertion Vector
                List <Line> el = new List <Line>();
                //Line[] lines = outlines[f].GetSegments();
                foreach (int j in orderedEdges)
                {
                    el.Add(outlines[f].SegmentAt(j));//el.Add(M.TopologyEdges.EdgeLine(fe[f][j]));
                }

                //Create Insertion Vector
                Vector3d vec = NGonsCore.VectorUtil.BisectorVector(el, outlines[f].AverageNormal(), false);
                faceVectors.Add(vec);


                List <GH_Path> paths = new List <GH_Path>();
                foreach (int j in orderedEdges)
                {
                    //edgeVectors.Add(fe[f][j],vec);
                    edgeVectors.Add(vec, new GH_Path(fe[f][j]));
                    paths.Add(new GH_Path(fe[f][j]));
                }

                faceEdgeID.Add(i, paths);
                //Rhino.RhinoApp.WriteLine(i.ToString() + " " + paths.Count.ToString());

                //A = el;
                //B = vec;
                //C = outlines[f].AverageNormal();
            }

            DataTree <Vector3d> EV    = mesh.insertionVectors(true);
            DataTree <Line>     edges = new DataTree <Line>();
            PointCloud          cloud = new PointCloud();

            //Check angles if vectors are not parallel to mesh edge
            foreach (GH_Path p in EV.Paths)
            {
                Line  line      = mesh.TopologyEdges.EdgeLine(p.Indices[0]);
                Plane edgePlane = new Plane(line.PointAt(0.5), mesh.GetMeshEdgePerpDir(p.Indices[0]));

                cloud.Add(line.PointAt(0.5), new Vector3d(p.Indices[0], 0, 0));

                double angledifference = Math.Abs(Vector3d.VectorAngle(line.Direction, edgeVectors.Branch(p)[0], edgePlane) % Math.PI);

                //Rhino.RhinoApp.WriteLine(angledifference.ToString());
                if (angledifference < angleTol || angledifference > (Math.PI - angleTol))
                {
                    edges.Add(new Line(line.PointAt(0.5), line.PointAt(0.5) + line.Direction.UnitVector() * line.Length * 0.25), p);
                    edges.Add(new Line(line.PointAt(0.5), line.PointAt(0.5) + edgeVectors.Branch(p)[0].UnitVector() * line.Length * 0.25), p);
                    edgeVectors.Branch(p)[0] = -EV.Branch(p)[0];
                }
                else
                {
                }
            }


            //Change insertion vectors
            if (customVectors.Count > 0)
            {
                for (int i = 0; i < customVectors.Count; i++)
                {
                    int edgeID = cloud.ClosestPoint(customVectors[i].From);
                    edgeVectors.Branch(new GH_Path((int)cloud[edgeID].Normal.X))[0] = customVectors[i].Direction;
                }
            }

            //Rhino.RhinoApp.WriteLine (faceEdgeID.Count.ToString());

            List <Vector3d> NGonsVectors = new List <Vector3d>()
            {
                Vector3d.ZAxis
            };

            for (int i = 1; i < faceEdgeID.Count; i++)
            {
                Vector3d vec = Vector3d.Zero;
                for (int j = 0; j < faceEdgeID[i].Count; j++)
                {
                    vec += edgeVectors.Branch(faceEdgeID[i][j])[0];
                }
                vec.Unitize();
                NGonsVectors.Add(vec);
            }

            DA.SetDataList(5, NGonsVectors);

            //EV = edgeVectors;
            DA.SetDataTree(2, edgeVectors);
            DA.SetDataTree(3, edges);
            //Get current face edges
            //Take edge only connected in current set
        }
예제 #18
0
            protected override void SolveInstance(IGH_DataAccess DA)
            {
                try {
                    //Input
                    Surface S = s;
                    //if (!DA.GetData(0, ref S)) { return; }
                    DA.GetData(0, ref S);
                    Point3d P = Point3d.Unset;

                    if (!DA.GetData(1, ref P))
                    {
                        P = S.PointAt(S.Domain(0).Mid, S.Domain(1).Mid);
                    }

                    double R = Rhino.RhinoMath.UnsetValue;
                    if (!DA.GetData(2, ref R))
                    {
                        return;
                    }

                    double A = Rhino.RhinoMath.UnsetValue;
                    if (!DA.GetData(3, ref A))
                    {
                        return;
                    }

                    int max = 0;
                    if (!DA.GetData(4, ref max))
                    {
                        return;
                    }

                    Boolean extend = false;
                    if (!DA.GetData(5, ref extend))
                    {
                        return;
                    }

                    if (R <= 0)
                    {
                        this.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Mesh edge length must be a positive, non-zero number.");
                        return;
                    }

                    Mesh cutter = new Mesh();
                    //DA.GetData(8, ref cutter);

                    Surface Sold = S;
                    Sold.SetDomain(0, new Interval(0, 1));
                    Sold.SetDomain(1, new Interval(0, 1));
                    PointCloud cornerPoints = new PointCloud(new Point3d[] { Sold.PointAt(0, 0), Sold.PointAt(0, 1), Sold.PointAt(1, 0), Sold.PointAt(1, 1) });


                    if (extend)   //Extend more and trim edges?
                    {
                        S = S.Extend(IsoStatus.North, R * 2, true);
                        S = S.Extend(IsoStatus.East, R * 2, true);
                        S = S.Extend(IsoStatus.South, R * 2, true);
                        S = S.Extend(IsoStatus.West, R * 2, true);
                    }

                    //int L = 0;
                    //int W = 0;
                    //DA.GetData(6, ref L);
                    //DA.GetData(7, ref W);

                    //----------------------------------------------------------------------------------------------------------//
                    //Solution

                    // starting point
                    double u0, v0;
                    S.ClosestPoint(P, out u0, out v0);

                    //Create plane on surface by point and surface normal, plane x,y axis are directions for the net
                    Plane plane = new Plane(S.PointAt(u0, v0), S.NormalAt(u0, v0));
                    plane.Rotate(Rhino.RhinoMath.ToRadians(A), S.NormalAt(u0, v0));
                    Vector3d[] dir = new Vector3d[] { plane.XAxis *R, plane.YAxis *R, plane.XAxis * -R, plane.YAxis * -R };

                    //Surface
                    Curve[] MyNakedEdges     = Sold.ToBrep().DuplicateNakedEdgeCurves(true, false);
                    Curve   SurfaceNakedEdge = Curve.JoinCurves(MyNakedEdges)[0];
                    Mesh[]  meshes           = new Mesh[] { new Mesh(), new Mesh(), new Mesh(), new Mesh() };

                    //----------------------------------------------------------------------------------------------------------//
                    //Create axis
                    // for each direction, walk out (and store list of points)

                    double           u, v;
                    List <Point3d>[] axis = new List <Point3d> [4];
                    List <Arc>[]     arcs = new List <Arc> [4];
                    polylines = new List <Polyline>();

                    for (int i = 0; i < 4; i++)
                    {
                        // set u and v to starting point
                        u = u0;
                        v = v0;
                        List <Point3d> pts        = new List <Point3d>();
                        List <Arc>     arcCurrent = new List <Arc>();


                        for (int j = 0; j < max + 1; j++)
                        {
                            Point3d pt = S.PointAt(u, v); // get point and normal for uv
                            pts.Add(pt);

                            Vector3d srfNormal = S.NormalAt(u, v) * R;

                            Arc arc = new Arc(pt + srfNormal, pt + dir[i], pt - srfNormal); // create forward facing arc and find intersection point with surface (as uv)
                            arcCurrent.Add(arc);
                            CurveIntersections isct = Intersection.CurveSurface(arc.ToNurbsCurve(), S, 0.01, 0.01);


                            if (isct.Count > 0)
                            {
                                isct[0].SurfacePointParameter(out u, out v);
                            }
                            else
                            {
                                break;
                            }

                            // adjust direction vector (new position - old position)
                            dir[i] = S.PointAt(u, v) - pt;
                        }

                        axis[i] = pts;
                        arcs[i] = arcCurrent;
                    }



                    //----------------------------------------------------------------------------------------------------------//
                    //Build up the mesh quads in between
                    Rhino.RhinoApp.ClearCommandHistoryWindow();

                    GH_PreviewUtil preview = new GH_PreviewUtil(GetValue("Animate", false));

                    Mesh         mesh                = new Mesh();                                                                                                                                                   // target mesh
                    Mesh[]       fourMeshes          = new Mesh[4];
                    List <int>[] faceID              = new List <int>[] { new List <int>(), new List <int>(), new List <int>(), new List <int>() };                                                                  //columns lengths
                    List <List <Polyline> >[] strips = new List <List <Polyline> >[] { new List <List <Polyline> >(), new List <List <Polyline> >(), new List <List <Polyline> >(), new List <List <Polyline> >() }; //columns lengths
                    //List<Polyline> cuts = new List<Polyline>();

                    for (int k = 0; k < 4; k++)   //Loop through each axis

                    {
                        Mesh qmesh = new Mesh();                                                         // local mesh for quadrant

                        Point3d[,] quad = new Point3d[axis[k].Count + 10, axis[(k + 1) % 4].Count + 10]; // 2d array of points
                        int[,] qindex   = new int[axis[k].Count + 10, axis[(k + 1) % 4].Count + 10];     // 2d array of points' indices in local mesh

                        int count = 0;

                        //Add 2nd axis particles
                        for (int i = 0; i < axis[(k + 1) % 4].Count; i++)
                        {
                            quad[0, i] = axis[(k + 1) % 4][i];        //store 2nd axis points in point array
                            qmesh.Vertices.Add(axis[(k + 1) % 4][i]); //also add 2nd axis points to mesh
                            qindex[0, i] = count++;                   //store indicies
                        }


                        for (int i = 1; i < quad.GetLength(0); i++)
                        {
                            if (i < axis[k].Count)              // add axis vertex
                            {
                                quad[i, 0] = axis[k][i];        //store 1st axis points in point array
                                qmesh.Vertices.Add(axis[k][i]); //also add 1st axis points to mesh
                                qindex[i, 0] = count++;         //store indicies
                            }


                            int counter = 0;

                            List <Polyline> currentStrip = new List <Polyline>();
                            // for each column attempt to locate a new vertex in the grid
                            for (int j = 1; j < quad.GetLength(1); j++)
                            {
                                // if quad[i - 1, j] doesn't exist, try to add it and continue (or else break the current row)
                                if (quad[i - 1, j] == new Point3d())
                                {
                                    if (j < 2)
                                    {
                                        break;
                                    }

                                    CurveIntersections isct = this.ArcIntersect(S, quad[i - 1, j - 1], quad[i - 1, j - 2], R);

                                    if (isct.Count > 0)
                                    {
                                        quad[i - 1, j] = isct[0].PointB;
                                        qmesh.Vertices.Add(quad[i - 1, j]);
                                        qindex[i - 1, j] = count++;
                                    }
                                    else
                                    {
                                        break;
                                    }
                                }

                                // if quad[i, j - 1] doesn't exist, try to create quad[i, j] by projection and skip mesh face creation
                                if (quad[i, j - 1] == new Point3d())
                                {
                                    if (i < 2)
                                    {
                                        break;
                                    }

                                    CurveIntersections isct = this.ArcIntersect(S, quad[i - 1, j], quad[i - 2, j], R);

                                    if (isct.Count > 0)
                                    {
                                        quad[i, j] = isct[0].PointB;
                                        qmesh.Vertices.Add(quad[i, j]);
                                        qindex[i, j] = count++;

                                        continue;
                                    }
                                }

                                // construct a sphere at each neighbouring vertex ([i,j-1] and [i-1,j]) and intersect

                                Sphere sph1 = new Sphere(quad[i, j - 1], R);
                                Sphere sph2 = new Sphere(quad[i - 1, j], R);
                                Circle cir;

                                if (Intersection.SphereSphere(sph1, sph2, out cir) == SphereSphereIntersection.Circle)
                                {
                                    CurveIntersections cin = Intersection.CurveSurface(NurbsCurve.CreateFromCircle(cir), S, 0.01, 0.01);// intersect circle with surface

                                    // attempt to find the new vertex (i.e not [i-1,j-1])

                                    foreach (IntersectionEvent ie in cin)
                                    {
                                        if ((ie.PointA - quad[i - 1, j - 1]).Length > 0.2 * R)  // compare with a tolerance, rather than exact comparison

                                        {
                                            quad[i, j] = ie.PointA;
                                            qmesh.Vertices.Add(quad[i, j]);
                                            qindex[i, j] = count++;

                                            Point3d[] facePt = new Point3d[] { quad[i, j], quad[i - 1, j], quad[i - 1, j - 1], quad[i, j - 1] };

                                            Sold.ClosestPoint(quad[i, j], out double u1, out double v1);
                                            Sold.ClosestPoint(quad[i - 1, j], out double u2, out double v2);
                                            Sold.ClosestPoint(quad[i - 1, j - 1], out double u3, out double v3);
                                            Sold.ClosestPoint(quad[i, j - 1], out double u4, out double v4);

                                            double tolerance = Rhino.RhinoDoc.ActiveDoc.ModelAbsoluteTolerance * 10;
                                            bool[] flag      = new bool[] {
                                                Sold.PointAt(u1, v1).DistanceTo(quad[i, j]) < tolerance,
                                                Sold.PointAt(u2, v2).DistanceTo(quad[i - 1, j]) < tolerance,
                                                Sold.PointAt(u3, v3).DistanceTo(quad[i - 1, j - 1]) < tolerance,
                                                Sold.PointAt(u4, v4).DistanceTo(quad[i, j - 1]) < tolerance
                                            };



                                            if (flag[0] && flag[1] && flag[2] && flag[3])
                                            {
                                                qmesh.Faces.AddFace(qindex[i, j], qindex[i - 1, j], qindex[i - 1, j - 1], qindex[i, j - 1]);// create quad-face
                                                currentStrip.Add(new Polyline()
                                                {
                                                    quad[i, j], quad[i - 1, j], quad[i - 1, j - 1], quad[i, j - 1], quad[i, j]
                                                });
                                                counter++;
                                            }
                                            else if (flag[0] || flag[1] || flag[2] || flag[3])
                                            {
                                                Polyline temp = new Polyline()
                                                {
                                                    quad[i, j], quad[i - 1, j], quad[i - 1, j - 1], quad[i, j - 1]
                                                };
                                                Polyline trimmedTemp = new Polyline();
                                                //temp = new Polyline() { quad[i, j], quad[i - 1, j], quad[i - 1, j - 1], quad[i, j - 1], quad[i, j] };

                                                double        t = R * 0.1;
                                                HashSet <int> intersectedSurfaceEdgeId = new HashSet <int>();


                                                for (int l = 0; l < 4; l++)
                                                {
                                                    //If point is ons surface
                                                    Sold.ClosestPoint(temp[l], out double cpu, out double cpv);
                                                    if (Sold.PointAt(cpu, cpv).DistanceTo(temp[l]) < Rhino.RhinoDoc.ActiveDoc.ModelAbsoluteTolerance)
                                                    {
                                                        trimmedTemp.Add(temp[l]);
                                                    }


                                                    //Intersect line segment with closed brep
                                                    Line faceSegment = new Line(temp[l], temp[MathUtil.Wrap(l + 1, 4)]);

                                                    Point3d[] meshLinePts = Intersection.MeshLine(cutter, faceSegment, out int[] faceIds);
                                                    if (meshLinePts.Length > 0)
                                                    {
                                                        trimmedTemp.Add(meshLinePts[0]);
                                                    }
                                                }


                                                trimmedTemp.Close();
                                                //cuts.Add(trimmedTemp);
                                            }

                                            break;
                                        }
                                    }

                                    if (preview.Enabled)
                                    {
                                        preview.Clear();
                                        preview.AddMesh(mesh);
                                        preview.AddMesh(qmesh);
                                        preview.Redraw();
                                    }
                                } //if sphere intersection
                            }     //for j

                            if (currentStrip.Count > 0)
                            {
                                strips[k].Add(currentStrip);
                            }
                        }//for i



                        mesh.Append(qmesh);// add local mesh to target
                        fourMeshes[k] = qmesh;
                    }//for k



                    //----------------------------------------------------------------------------------------------------------//
                    //Output



                    mesh.Weld(Math.PI);
                    mesh.Compact();
                    mesh.Normals.ComputeNormals();

                    DA.SetData(0, mesh);
                    DA.SetDataTree(1, NGonsCore.GrasshopperUtil.IE2(axis, 0));

                    this.PreparePreview(mesh, DA.Iteration, null, true, null, mesh.GetEdges());
                    //DA.SetDataList(2, cuts);
                    //DA.SetDataTree(3, NGonsCore.GrasshopperUtil.IE4(patches.ToList(), 0));
                    //DA.SetDataList(4, fourMeshes);
                    //DA.SetDataTree(5, GrasshopperUtil.IE3(strips, 0));

                    preview.Clear();
                }catch (Exception e) {
                    GrasshopperUtil.Debug(e);
                }
            }