예제 #1
0
        //http://www.pointclouds.org/documentation/tutorials/normal_estimation.php
        //https://www.cloudcompare.org/doc/wiki/index.php?title=Normals%5CCompute



        public static List <Vector3d> LineCloudNormals(DataTree <Line> lines, DataTree <int> adj)
        {
            List <Vector3d> _Normals = new List <Vector3d>();

            //Compute bounding box of cloud
            BoundingBox bbox = new BoundingBox();

            foreach (Line l in lines.AllData())
            {
                bbox.Union(l.From);
                bbox.Union(l.To);
            }

            bbox.Inflate(100);
            Point3d p = bbox.PointAt(0.5, 0.5, 1);



            //Iterate through joints



            //Fit to Plane

            //Add all lines point to a base datatree
            DataTree <Point3d> pts = new DataTree <Point3d>();

            for (int i = 0; i < lines.BranchCount; i++)
            {
                pts.Add(lines.Branch(i)[0].From, new GH_Path(i));
                pts.Add(lines.Branch(i)[0].To, new GH_Path(i));
            }

            //Add only second object point to first object path
            for (int i = 0; i < adj.BranchCount; i++)
            {
                int id0 = adj.Branch(i)[0];
                int id1 = adj.Branch(i)[1];

                pts.Add(lines.Branch(id1)[0].From, new GH_Path(id0));
                pts.Add(lines.Branch(id1)[0].To, new GH_Path(id0));
            }

            //Orient Plane
            for (int i = 0; i < pts.BranchCount; i++)
            {
                Plane.FitPlaneToPoints(pts.Branch(i), out Plane plane);
                plane.Origin = (pts.Branch(i)[0] + pts.Branch(i)[1]) * 0.5;
                if ((plane.Origin + plane.Normal).DistanceToSquared(p) > (plane.Origin - plane.Normal).DistanceToSquared(p))
                {
                    plane.Flip();
                }
                _Normals.Add(plane.Normal);
            }



            return(_Normals);
        }
예제 #2
0
    //Thic function replicate SandBox lines topology
    //As inputs there are lines
    //Tolerance is used to glued points thar are close to each others
    //Outputs are
    //points list of Point3d
    //linePoint dataTree containing the points index number for end and beginning of the line
    //pointPoint dataTree containing the points index number for each other point connected to this point
    public static void LineTopology(List <Line> lines, double tolerance, ref List <Point3d> points, ref DataTree <int> linePoint, ref DataTree <int> pointPoint, ref DataTree <int> pointLine)
    {
        for (int n_line = 0; n_line < lines.Count; n_line++)
        {
            bool addPoint = true;
            int  nPoint   = 0;
            for (int i = 0; i < points.Count; i++)
            {
                if (points[i].DistanceTo(lines[n_line].From) < tolerance)
                {
                    addPoint = false;
                    nPoint   = i;
                }
            }
            if (addPoint)
            {
                points.Add(lines[n_line].From);
                linePoint.Add(points.Count - 1, new GH_Path(n_line));
            }
            else
            {
                linePoint.Add(nPoint, new GH_Path(n_line));
            }

            addPoint = true;
            for (int i = 0; i < points.Count; i++)
            {
                if (points[i].DistanceTo(lines[n_line].To) < tolerance)
                {
                    addPoint = false;
                    nPoint   = i;
                }
            }
            if (addPoint)
            {
                points.Add(lines[n_line].To);
                linePoint.Add(points.Count - 1, new GH_Path(n_line));
            }
            else
            {
                linePoint.Add(nPoint, new GH_Path(n_line));
            }
        }
        for (int n_line = 0; n_line < linePoint.BranchCount; n_line++)
        {
            pointPoint.Add(linePoint.Branches[n_line][0], new GH_Path(linePoint.Branches[n_line][1]));
            pointPoint.Add(linePoint.Branches[n_line][1], new GH_Path(linePoint.Branches[n_line][0]));
        }

        for (int j = 0; j < linePoint.BranchCount; j++)
        {
            pointLine.Add(j, new GH_Path(linePoint.Branch(j)[0]));
            pointLine.Add(j, new GH_Path(linePoint.Branch(j)[1]));
        }
    }
예제 #3
0
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            ///////////////////////////////////////////////////////////////////////////////////////////////////声明变量
            List <Curve> c  = new List <Curve>();
            double       t1 = 0;
            double       t2 = 0;

            ///////////////////////////////////////////////////////////////////////////////////////////////////检测输入端是否合理
            if (!DA.GetDataList(0, c))
            {
                return;
            }
            if (!DA.GetData(1, ref t1))
            {
                return;
            }
            if (!DA.GetData(2, ref t2))
            {
                return;
            }
            DataTree <Curve>   last     = new DataTree <Curve>();
            DataTree <Point3d> collects = ViperClass.EmptyTree(c.Count);
            int index  = 0;
            int branch = DA.Iteration;

            for (int i = 0; i < c.Count; i++)
            {
                for (int q = i + 1; q < c.Count; q++)
                {
                    Rhino.Geometry.Intersect.CurveIntersections result = Rhino.Geometry.Intersect.Intersection.CurveCurve(c[i], c[q], t1, t2);
                    if (result.Count > 0)                      ////有交集
                    {
                        for (int k = 0; k < result.Count; k++) ////记录每次相交的t值并分别赋值给两曲线
                        {
                            collects.Branch(i).Add((result[k].PointA));
                            collects.Branch(q).Add((result[k].PointB));
                        }
                    }
                }
            }
            /////////////////////////////////////////////////////////////////////////////////////////////////
            for (int i = 0; i < c.Count; i++)
            {
                if (collects.Branch(i).Count == 0)
                {
                    last.Add(c[i], new GH_Path(0, branch, index));
                    index++;
                    continue;
                }
                last.AddRange(ViperClass.SplitByPts(c[i], collects.Branch(i).ToList()), new GH_Path(0, branch, index));
                index++;
            }
            DA.SetDataTree(0, last);
        }
예제 #4
0
    private void RunScript(DataTree <Plane> iWrap, DataTree <Plane> iAllPlanes, DataTree <Plane> iTravelPlanes, ref object oProjectedPlanes, ref object oDebug, ref object oDebugB)
    {
        // <Custom code>

        DataTree <int> iWrapCounts = new DataTree <int>();

        for (int i = 0; i < iWrap.BranchCount; i++)
        {
            GH_Path pth = new GH_Path(i);
            iWrapCounts.Add(iWrap.Branch(i).Count, pth);
        }

        DataTree <int> iTravelCounts = new DataTree <int>();

        for (int i = 0; i < iTravelPlanes.BranchCount; i++)
        {
            GH_Path pth = new GH_Path(i);
            iTravelCounts.Add(iTravelPlanes.Branch(i).Count, pth);
        }

        DataTree <int> iSelectionIndexes = new DataTree <int>();

        for (int i = 0; i < iTravelCounts.BranchCount; i++)
        {
            GH_Path pth = new GH_Path(i);
            for (int y = 0; y < iTravelCounts.Branch(i)[0]; y++)
            {
                iSelectionIndexes.Add(iWrapCounts.Branch(i)[0] + y, pth);
            }
        }

        DataTree <Plane> projectedPlanes = new DataTree <Plane>();

        for (int i = 0; i < iAllPlanes.BranchCount; i++)
        {
            GH_Path pth = new GH_Path(i);
            for (int y = 0; y < iSelectionIndexes.Branch(i).Count; y++)
            {
                Plane tempPlane  = iAllPlanes.Branch(i)[iSelectionIndexes.Branch(i)[y]];
                Plane tempPlane2 = iTravelPlanes.Branch(i)[y];
                tempPlane2.Origin = tempPlane.Origin;
                projectedPlanes.Add(tempPlane2, pth);
                iAllPlanes.Branch(i)[iSelectionIndexes.Branch(i)[y]] = tempPlane2;
            }
        }

        oProjectedPlanes = iAllPlanes;
        oDebug           = iWrapCounts;
        oDebugB          = projectedPlanes;
        // </Custom code>
    }
예제 #5
0
        public static List <List <Point3d> > TreeToList(DataTree <Point3d> Points)
        {
            List <List <Point3d> > outPoints = new List <List <Point3d> >();

            for (int i = 0; i < Points.BranchCount; i++)
            {
                List <Point3d> temppoints = new List <Point3d>();

                for (int j = 0; j < Points.Branch(i).Count; j++)
                {
                    temppoints.Add(Points.Branch(i)[j]);
                }
                outPoints.Add(temppoints);
            }
            return(outPoints);
        }
예제 #6
0
        /// <summary>
        /// Draws a gradient trail through the display pipeline
        /// </summary>
        /// <param name="args">preview Display Args for IGH_PreviewObjects</param>
        /// <param name="particleSet">The data tree containing the points list for each object you want to draw a gradient for</param>
        /// <param name="colorType">the color type</param>
        /// <param name="minTrailThickness">the minimum trail thickness</param>
        /// <param name="maxTrailThickness">the maximum trail thickness</param>
        public void DrawGradientTrails(IGH_PreviewArgs args, DataTree <Point3d> particleSet, int colorType, float minTrailThickness, float maxTrailThickness)
        {
            Color color = args.WireColour;

            for (int i = 0; i < particleSet.BranchCount; i++)
            {
                List <Point3d> ptlist = particleSet.Branch(i);
                //-------DRAW TRAILS AS SEGMENTS WITH CUSTOM STROKE WIDTH---------
                if (ptlist.Count > 0)
                {
                    for (int x = 0; x < ptlist.Count; x++)
                    {
                        if (x != 0)
                        {
                            float stroke     = CulebraData.Utilities.Mapping.Map(x / (1.0f * ptlist.Count), 0.0f, 1.0f, minTrailThickness, maxTrailThickness);
                            float colorValue = CulebraData.Utilities.Mapping.Map(x / (1.0f * ptlist.Count), 0.0f, 1.0f, 0f, 255.0f);
                            if (colorType == 0)
                            {
                                args.Display.DrawLine(ptlist[x - 1], ptlist[x], Color.FromArgb(0, (int)colorValue, 0, 100), (int)stroke);
                            }
                            else if (colorType == 1)
                            {
                                args.Display.DrawLine(ptlist[x - 1], ptlist[x], Color.FromArgb(0, 0, 255, (int)colorValue), (int)stroke);
                            }
                            else
                            {
                                args.Display.DrawLine(ptlist[x - 1], ptlist[x], Color.FromArgb(0, 255, 255, (int)colorValue), (int)stroke);
                            }
                        }
                    }
                }
            }
        }
예제 #7
0
        protected override void SetOutputs(IGH_DataAccess da)
        {
            outTree = new DataTree <Point3d>();
            GH_Path trunk  = new GH_Path(0); // {0}
            GH_Path branch = new GH_Path();  // {}\
            GH_Path limb   = new GH_Path();


            for (int i = 0; i < particles.Count; i++)
            {
                IQuelea particle = particles[i];
                branch = trunk.AppendElement(i);
                DataTree <Point3d> particlePositionHistoryTree = particle.Position3DHistory.ToTree();

                for (int j = 0; j < particlePositionHistoryTree.BranchCount; j++)
                {
                    limb = branch.AppendElement(j);
                    //for (int k = particlePositionHistoryTree.Branch(j).Count - 1; k >= 0; k--)
                    //{
                    //  outTree.Add(particlePositionHistoryTree.Branch(j)[k], limb);
                    //}
                    outTree.AddRange(particlePositionHistoryTree.Branch(j), limb);
                }
            }
            da.SetDataTree(nextOutputIndex++, outTree);
        }
예제 #8
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            List <string> colList = new List <string>();
            string        path    = "";

            DA.GetData(IN_imagePath, ref path);
            DA.GetDataList(IN_colList, colList);

            imageProcessor = new ImageProcessor(path, colList);

            var areaPts          = imageProcessor._areaPoints;
            var programCentroids = imageProcessor._progCentroids;
            var perimPts         = imageProcessor._ProcessedPts;

            BoundaryExtractor engine = new BoundaryExtractor(perimPts, programCentroids);

            var ptTree = engine.outTree;

            //temp polylineTree
            DataTree <Polyline> treeInterim = new DataTree <Polyline>();

            for (int i = 0; i < ptTree.BranchCount; i++)
            {
                Polyline poly = new Polyline();
                poly.AddRange(ptTree.Branch(i));
                poly.Add(ptTree.Branch(i)[0]);
                treeInterim.Add(poly, new GH_Path(ptTree.Path(i).Indices[0]));
            }

            //final output tree
            DataTree <Polyline> treeOut = new DataTree <Polyline>();

            for (int i = 0; i < treeInterim.BranchCount; i++)
            {
                if (treeInterim.Branch(i).Count == 2)
                {
                    treeOut.Add(treeInterim.Branch(i).OrderByDescending(l => l.Length).ToArray()[0], new GH_Path(treeInterim.Path(i)));
                }
                else
                {
                    treeOut.AddRange(treeInterim.Branch(i), new GH_Path(treeInterim.Path(i)));
                }
            }

            DA.SetDataTree(OUT_polyTree, treeOut);
        }
예제 #9
0
        protected override void RegisterInputParams(GH_InputParamManager pManager)
        {
            var t = new DataTree <int>();
            var a = t.Branch();

            _keyIn   = pManager.AddTextParameter("Key", "K", "Key", GH_ParamAccess.list);
            _valueIn = pManager.AddTextParameter("Value", "V", "Value", GH_ParamAccess.list);
        }
    // <Custom additional code>
    public void IdentifyPinIndexes(WindingClass wC, DataTree <Point3d> anchors)
    {
        // Find pin index

        double minDistancePin = double.MaxValue;

        for (var i = 0; i < anchors.Branch(wC.edgeIndex).Count; i++)
        {
            Point3d pt          = wC.basePlane.Origin;
            double  distancePin = pt.DistanceTo(anchors.Branch(wC.edgeIndex)[i]);
            if (distancePin < minDistancePin)
            {
                minDistancePin = distancePin;
                wC.pinIndex    = i;
            }
        }
    }
예제 #11
0
        public void Add(Point3d position, bool wrapped)
        {
            if (Count >= size)
            {
                tree.Branch(0).RemoveAt(0);

                if (tree.Branch(0).Count == 0)
                {
                    tree.RemovePath(tree.Path(0));
                }
            }
            if (wrapped)
            {
                nextPathIndex++;
            }
            tree.Add(position, new GH_Path(nextPathIndex));
        }
예제 #12
0
파일: KMap.cs 프로젝트: M-JULIANI/planbeeGH
 //    public Input(int num)
 //    {
 //      w = new double[num];
 //      for (int i = 0; i < num; i++)
 //        w[i] = rnd.NextDouble();
 //    }
 //extracting the program data (6 programs) and assigning weights per the data
 public Input(int num, int branch, DataTree <double> _pData)
 {
     w = new double[num];
     for (int j = 0; j < num; j++)
     {
         var b = _pData.Branch(branch);
         w[j] = b[j];
     }
 }
예제 #13
0
 public BoundaryExtractor(DataTree <Point3d> pTree, Point3d [] centList)
 {
     pointTree = pTree;
     outTree   = new DataTree <Point3d>();
     // centroids = new List<Point3d>();
     for (int i = 0; i < pointTree.BranchCount; i++)
     {
         BranchWork(pointTree.Branch(i), i, centList[i]);
     }
 }
예제 #14
0
파일: KMap.cs 프로젝트: M-JULIANI/planbeeGH
        public KMap(DataTree <double> ProgramInputs, List <Point3d> NodePts, double resolution, DataTree <double> NodeData, int numW, double learn, List <double> radMultiplier, double BMUradMultiplier, int maxIterations) // BMU rad might want to be smaller than radMultiplier
        {
            m_pNames      = new List <string>();
            this.numNodes = NodePts.Count;
            learning      = learn;
            radius        = radMultiplier;
            inputW        = new DataTree <double>();
            progInputs    = ProgramInputs;
            applyProgramInputs(radius.Count);

            bmuMultiplier = BMUradMultiplier;
            maxIters      = maxIterations;

            this.numWeights = numW;

            cRadius = resolution / 2.0;

            nodeW        = new DataTree <double>();
            nodeWeights  = new List <double>();
            nodePoints   = new List <Point3d>();
            nodePoints   = NodePts;
            tree         = new DataTree <Polyline>();
            drawingPolys = new List <Polyline>();
            _nodeData    = new DataTree <double>();
            _nodeData    = NodeData;
            discreteCol  = new List <System.Drawing.Color>();
            iter         = 0;



            nodes = new Node[numNodes];



            double average = 0.0;

            for (int i = 0; i < radius.Count; i++)
            {
                average += radius[i];
            }

            average /= radius.Count;

            for (int i = 0; i < numNodes; i++)
            {
                var pt = nodePoints[i];
                nodes[i] = new Node(pt, _nodeData.Branch(i));
            }
            timeConstant = maxIters / Math.Log(average);

            for (int i = 0; i < inputs.Length; i++)
            {
                radiusDecay.Add(radius[i]);
            }
        }
예제 #15
0
        static List <List <T> > TreeToListOfLists <T>(DataTree <T> tree)
        {
            List <List <T> > list = new List <List <T> >();

            foreach (GH_Path p in tree.Paths)
            {
                List <T> l = tree.Branch(p);
                list.Add(l);
            }
            return(list);
        }
예제 #16
0
        public void GetPointBoundaries(out List <string> length)
        {
            _ProcessedPts = new DataTree <Point3d>();

            length = new List <string>();

            for (int i = 0; i < _areaPoints.BranchCount; i++)
            {
                var outPts = ExtractPerimeterPts(_areaPoints.Branch(i));
                _ProcessedPts.AddRange(outPts, new GH_Path(i));
                length.Add(outPts.Count.ToString());
            }
        }
        /// <summary>
        /// Write XML
        ///string settings_path = @"C:\Users\petra\AppData\Roaming\Grasshopper\6\Libraries\RhinoJoint\TileTypeSettings.xml";
        ///TilesToXML(male, female, type, settings_path);
        /// </summary>
        /// <param name="male"></param>
        /// <param name="female"></param>
        /// <param name="type"></param>
        /// <param name="settings_path"></param>
        public static void TilesToXML(DataTree <Polyline> male, DataTree <Polyline> female, DataTree <string> type, string settings_path)
        {
            System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.InvariantCulture;
            //string settings_path = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location), "TileTypeSettings.xml");

            var root = new XElement("Tile");

            for (int i = 0; i < type.BranchCount; i++)
            {
                if (male.Branch(i).Count == 0)
                {
                    continue;
                }
                var tileXML = PolylinesToXML(male.Branch(i), female.Branch(i), type.Branch(i)[0]);
                root.Add(tileXML);
            }

            //1. Add root to document
            XDocument doc = new XDocument(root);

            doc.Save(settings_path);
        }
예제 #18
0
        private IGH_DataTree GeometryTree <T>(DataTree <T> output)
        {
            DataTree <object> newOutput = new DataTree <object>();

            for (int b = 0; b < output.BranchCount; b++)
            {
                var p             = output.Path(b);
                var currentBranch = output.Branch(b);
                var newBranch     = GeometryList(currentBranch);
                newOutput.AddRange(newBranch, p);
            }
            return(newOutput);
        }
예제 #19
0
        public void CreateCurves()
        {
            //Curve At Top
            #region PointsAtTop

            List <Point3d> _PointsAtTop = new List <Point3d>(PointsAtTop);
            _PointsAtTop.Add(PointsAtTop[0]);
            CurvesAtTop.Add(Curve.CreateControlPointCurve(_PointsAtTop));

            #endregion PointsAtTop

            //Curve AT Bottom
            #region PointsAtBottom

            List <Point3d> _PointsAtBottom = new List <Point3d>(PointsAtBottom);
            _PointsAtBottom.Add(PointsAtBottom[0]);
            CurvesAtBottom.Add(Curve.CreateControlPointCurve(_PointsAtBottom));

            #endregion PointsAtBottom

            //Curve AT Top Plate
            #region PointsAtTopPlate
            if (PointsAtTopPlate != null)
            {
                List <Point3d> _PointsAtTopPlate = new List <Point3d>(PointsAtTopPlate);
                _PointsAtTopPlate.Add(PointsAtTopPlate[0]);
                CurvesAtTopPlate.Add(Curve.CreateControlPointCurve(_PointsAtTopPlate));
            }
            #endregion PointsAtTopPlate

            //Curves At Bottom Plate
            #region PointsAtBottomPlate
            if (PointsAtBottomPlate != null)
            {
                List <Point3d> _PointsAtBottomPlate = new List <Point3d>(PointsAtBottomPlate);
                _PointsAtBottomPlate.Add(PointsAtBottomPlate[0]);
                CurvesAtBottomPlate.Add(Curve.CreateControlPointCurve(_PointsAtBottomPlate));
            }
            #endregion PointsAtBottomPlate

            //Curves At Loop
            #region PointsAtLoop

            for (int i = 0; i < PointsAtLoop.BranchCount; i++)
            {
                CurvesAtLoop.Add(Curve.CreateControlPointCurve(PointsAtLoop.Branch(i), 3));
            }

            #endregion PointsAtLoop
        }
예제 #20
0
 protected override void SolveInstance(IGH_DataAccess da)
 {
     if (!GetInputs(da))
     {
         return;
     }
     if (reset == true)
     {
         trailTree = new DataTree <Point3d>();
         iter      = 0;
         maxid     = 0;
     }
     else
     {
         foreach (Amoeba amo in p.population)
         {
             GH_Path thispath = new GH_Path(amo.ID);
             if (amo.ID > maxid)
             {
                 trailTree.Add(amo.prev_loc, thispath);
                 maxid = amo.ID;
             }
             trailTree.Add(amo.Location, thispath);
             if (trailTree.Branch(thispath).Count > history)
             {
                 trailTree.Branch(thispath).RemoveAt(0);
             }
         }
         foreach (int id in p._todie_id)
         {
             GH_Path thispath = new GH_Path(id);
             trailTree.Branch(thispath).Clear();
         }
         iter++;
     }
     SetOutputs(da);
 }
예제 #21
0
// ===============================================================================================
// reorganized certain indices in a list of 4 itemss
// ===============================================================================================
        public static DataTree <T> ReOrganize2 <T>(DataTree <T> tree)
        {
            for (int i = 0; i < tree.BranchCount; i++)
            {
                var temp1 = tree.Branch(i)[2];
                var temp2 = tree.Branch(i)[3];
                tree.Branch(i)[2] = temp2;
                tree.Branch(i)[3] = temp1;

                temp1 = tree.Branch(i)[4];
                temp2 = tree.Branch(i)[5];

                tree.Branch(i)[4] = temp2;
                tree.Branch(i)[5] = temp1;
            }
            return(tree);
        }
예제 #22
0
 /// <summary>
 /// Draws a polyline trail through the display pipeline
 /// </summary>
 /// <param name="args">preview Display Args for IGH_PreviewObjects</param>
 /// <param name="particleSet">The data tree containing the points list for each object you want to draw a gradient for</param>
 /// <param name="dottedPolyline">do you want a dotted polyline</param>
 /// <param name="thickness">the thickness of the trail</param>
 /// <param name="color">the color of the trail</param>
 public void DrawPolylineTrails(IGH_PreviewArgs args, DataTree <Point3d> particleSet, bool dottedPolyline, int thickness, System.Drawing.Color color)
 {
     for (int i = 0; i < particleSet.BranchCount; i++)
     {
         List <Point3d> ptlist = particleSet.Branch(i);
         if (dottedPolyline)
         {
             args.Display.DrawDottedPolyline(ptlist, color, false);
         }
         else
         {
             args.Display.DrawPolyline(ptlist, color, thickness);
         }
     }
 }
        private DataTree <Vector3d> GetMemberDisplacementsByType(int result_type)
        {
            var oDisplacementsByType = new DataTree <Vector3d>();

            for (int i = 0; i < _memberdisplacements.Paths.Count; i++)
            {
                if (_memberdisplacements.Paths[i].Indices[1] == result_type)
                {
                    var oldPath = _memberdisplacements.Paths[i];
                    var gh_path = new GH_Path(oldPath.Indices[0]);
                    oDisplacementsByType.AddRange(_memberdisplacements.Branch(oldPath), gh_path);
                }
            }
            return(oDisplacementsByType);
        }
예제 #24
0
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            Sheet sheet = null;

            if (!DA.GetData(0, ref sheet))
            {
                return;
            }

            DA.SetData(0, sheet.Properties.Title);
            DA.SetData(1, sheet.Properties.SheetId);
            DA.SetData(2, sheet.Properties.Index);

            // empty tree for cell strings
            DataTree <string> rowsTree = new DataTree <string>();


            // extract strings, add to tree
            var rowData = sheet.Data[0].RowData;

            for (int i = 0; i < rowData.Count; i++)
            {
                // create new branch
                rowsTree.Insert("", new GH_Path(i), 0);
            }
            // clear dummy data
            rowsTree.ClearData();

            for (int i = 0; i < rowData.Count; i++)
            {
                List <string> rowStrings = new List <string>();
                if (!(rowData[i].Values is null))
                {
                    foreach (var value in rowData[i].Values)
                    {
                        //rowStrings.Add(value.EffectiveValue?.ToDataString());
                        rowStrings.Add(value.FormattedValue);
                    }
                }
                rowsTree.Branch(i).AddRange(rowStrings);
            }

            // set row data
            DA.SetDataTree(3, rowsTree);
        }
예제 #25
0
	}//eof




	/// <summary>
    /// This is the method that actually does the work.
	/// </summary>
	protected override void SolveInstance(IGH_DataAccess DA)
	{
		List<Curve> crv = new List<Curve>();
		if (!DA.GetDataList(0, crv)) return;

		DataTree<Curve> r = new DataTree<Curve>();

		for (int i = 0; i < crv.Count; ++i)
		{
			if (!isChildOfCrv(crv[i], crv))
			{
				GH_Path p = new GH_Path(0);
				r.Add(crv[i], p);
			}
		}

		bool isAnyCrvAligned = true;

		while (isAnyCrvAligned)
		{
			isAnyCrvAligned = false;
			int BC = r.BranchCount;
			for (int i = 0; i < BC; ++i)
			{
				for (int j = 0; j < crv.Count; ++j)
				{
					if (r.AllData().IndexOf(crv[j]) == -1)
					{
						GH_Path p = new GH_Path(i + 1);
						if (isChildOfCrv(crv[j], r.Branch(i)))
						{
							r.Add(crv[j], p);
							isAnyCrvAligned = true;
						}
					}
				}
			}
		}

		DA.SetDataTree(0, r);
	}//eof
        private DataTree <Mesh> GetDeformedMeshes(double scale, ref List <string> msg)
        {
            var oMeshes = new DataTree <Mesh>();

            // Same tree structure as displacements
            foreach (var path in _meshdisplacements.Paths)
            {
                var gh_path   = new GH_Path(path);
                var mesh_path = new GH_Path(path.Indices[0]);
                // Get fe mesh as starting mesh
                var mesh = _feMeshes.Branch(mesh_path)[0].DuplicateMesh();
                // Move FE Nodes according to displacements
                for (int i = 0; i < mesh.Vertices.Count; i++)
                {
                    mesh.Vertices[i] += (Point3f)(Point3d)(scale * _meshdisplacements.Branch(path)[i]); // -_-
                }
                // Add mesh to tree
                oMeshes.Add(mesh, gh_path);
            }
            return(oMeshes);
        }
예제 #27
0
        public static void IntersectBreps(DataTree <Brep> panels, DataTree <Brep> foundations, ref DataTree <Polyline> panelsCuts, ref DataTree <Polyline> foundationsCuts)
        {
            panelsCuts      = new DataTree <Polyline>();
            foundationsCuts = new DataTree <Polyline>();


            // try {



            for (int i = 0; i < panels.BranchCount; i++)
            {
                for (int j = 0; j < foundations.BranchCount; j++)
                {
                    Polyline[] intersection0 = new Polyline[0];
                    Polyline[] intersection1 = new Polyline[0];



                    bool isIntersecting = IntersectBreps2x2(panels.Branch(i), foundations.Branch(j), ref intersection0, ref intersection1);



                    if (isIntersecting && intersection0.Length != 0 && intersection1.Length != 0)
                    {
                        Rhino.RhinoDoc.ActiveDoc.Objects.AddPolyline(intersection0[0]);
                        panelsCuts.AddRange(intersection0, new GH_Path(i));
                        foundationsCuts.AddRange(intersection1, new GH_Path(j));
                    }
                }
            }


            //} catch (Exception e) {
            //    Print(e.ToString());
            //}

            //A = panelsCuts;
            //B = foundationsCuts;
        }
예제 #28
0
        /// <summary>
        /// Draws a disco trail through the display pipeline. Trails flash different colors throughout the simulation
        /// </summary>
        /// <param name="args">preview Display Args for IGH_PreviewObjects</param>
        /// <param name="particleSet">The data tree containing the points list for each object you want to draw a gradient for</param>
        /// <param name="randomGen">an instance of the random class</param>
        /// <param name="minTrailThickness">the minimum trail thickness</param>
        /// <param name="maxTrailThickness">the maximum trail thickness</param>
        public void DrawDiscoTrails(IGH_PreviewArgs args, DataTree <Point3d> particleSet, Random randomGen, float minTrailThickness, float maxTrailThickness)
        {
            Color color = args.WireColour;

            for (int i = 0; i < particleSet.BranchCount; i++)
            {
                List <Point3d> ptlist = particleSet.Branch(i);
                //-------DRAW TRAILS AS SEGMENTS WITH CUSTOM STROKE WIDTH---------
                Color randomColorAction = CulebraData.Utilities.ColorUtility.GetRandomColor(randomGen);
                if (ptlist.Count > 0)
                {
                    for (int x = 0; x < ptlist.Count; x++)
                    {
                        if (x != 0)
                        {
                            float stroke = CulebraData.Utilities.Mapping.Map(x / (1.0f * ptlist.Count), 0.0f, 1.0f, minTrailThickness, maxTrailThickness);
                            args.Display.DrawLine(ptlist[x - 1], ptlist[x], randomColorAction, (int)stroke);
                        }
                    }
                }
            }
        }
        private DataTree <Curve> GetDeformedMembers(double scale, ref List <string> msg)
        {
            var oCurves = new DataTree <Curve>();

            // Same tree structure as displacements
            foreach (var path in _memberdisplacements.Paths)
            {
                var gh_path     = new GH_Path(path);
                var member_path = new GH_Path(path.Indices[0]);
                // Get deformed control points
                var ctrlPoints     = _controlPoints.Branch(member_path);
                var deformations   = _memberdisplacements.Branch(path);
                var deformedPoints = new List <Point3d>();
                for (int i = 0; i < ctrlPoints.Count; i++)
                {
                    deformedPoints.Add(new Point3d(ctrlPoints[i] + scale * deformations[i]));
                }
                // Add curve to tree
                var memberShape = Curve.CreateControlPointCurve(deformedPoints);
                oCurves.Add(memberShape, gh_path);
            }
            return(oCurves);
        }
예제 #30
0
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            HeGraph3d graph       = null;
            double    layerHeigth = 0;

            if (!DA.GetData(0, ref graph))
            {
                return;
            }
            if (!DA.GetData(1, ref layerHeigth))
            {
                return;
            }

            var frames  = new DataTree <Plane>();
            var tparams = new DataTree <double>();

            for (int i = 0; i < graph.Edges.Count; i++)
            {
                frames.AddRange(getEdgeFrames(graph, i, layerHeigth), new GH_Path(i));
            }

            for (int i = 0; i < graph.Edges.Count; i++)
            {
                var count = frames.Branch(i).Count;
                var t0    = 1.0 / (double)count;

                for (int j = 0; j < count; j++)
                {
                    tparams.Add((j * t0), new GH_Path(i));
                }
            }

            DA.SetDataTree(0, frames);
            DA.SetDataTree(1, tparams);
        }
예제 #31
0
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            //---- Declareing ---------------------------------------------------------------------------
            GH_Structure<GH_Brep> AllStripes;
            DA.GetDataTree("Triloop Stipes", out AllStripes);

            GH_Structure<GH_Point> AllPoints;
            DA.GetDataTree("Points", out AllPoints);

            bool Reorient = false;
            DA.GetData<bool>("Merge Stripes", ref Reorient);

            bool Switch = false;
            DA.GetData<bool>("Switch", ref Switch);

            int Seam = 0;
            DA.GetData<int>("Seam", ref Seam);

            DataTree<Brep> AllUnrolledBreps = new DataTree<Brep>();
            DataTree<Brep> ForReorientBreps = new DataTree<Brep>();
            DataTree<Plane> AllOrientPlanes = new DataTree<Plane>();
            DataTree<Curve> AllSharedCurves = new DataTree<Curve>();
            DataTree<Point3d> AllUnrolledPoints = new DataTree<Point3d>();

            //---- End Declareing -----------------------------------------------------------------------
            //---- Functions ----------------------------------------------------------------------------

            #region Unroll

            for (int i = 0; i < AllStripes.Branches.Count; i++)
            {
                GH_Path pth = new GH_Path(i);
                GH_Path originalPath = AllStripes.Paths[i];
                int stripecounter = 0;

                foreach (GH_Brep gbrep in AllStripes[i])
                {
                    Unroller unroll = new Unroller(gbrep.Value);
                    // Add points to unroll with
                    if (AllPoints.Branches.Count != 0)
                    {
                        foreach (GH_Point pt in AllPoints[i])
                        { unroll.AddFollowingGeometry(pt.Value); }
                    }

                    unroll.ExplodeOutput = false;

                    Curve[] curves;
                    Point3d[] unrolledPoints;
                    TextDot[] dots;
                    Brep[] unrolledBreps = unroll.PerformUnroll(out curves, out unrolledPoints, out dots);

                    if (Reorient == false)
                    {
                        foreach (Brep b in unrolledBreps)
                        { AllUnrolledBreps.Add(b, originalPath); }

                        foreach (Point3d p in unrolledPoints)
                        { AllUnrolledPoints.Add(p, originalPath); }
                    }

                    else
                    {
                        foreach (Brep b in unrolledBreps)
                        { AllUnrolledBreps.Add(b, pth.AppendElement(stripecounter)); }
                    }

                    // For reorientation
                    if (Reorient == true)
                    { ForReorientBreps.Add(unrolledBreps[Seam], pth); }

                    stripecounter++;
                }
            }
            #endregion unroll

            if (Reorient == true)
            {
                //ForReorientBreps.Branch(0)[0].Curves3D[0].PointAtEnd;

                for (int i = 0; i < ForReorientBreps.BranchCount; i++)
                {
                    GH_Path pth = new GH_Path(i);

                    foreach (Curve crv0 in ForReorientBreps.Branch(i)[0].Curves3D)
                    {
                        foreach (Curve crv1 in ForReorientBreps.Branch(i)[1].Curves3D)
                        {
                            double l0 = crv0.GetLength();
                            double l1 = crv1.GetLength();

                            if (Math.Abs(l0 - l1) < 0.00001)
                            {

                                // orient crv0
                                Plane origin0 = new Plane(new Point3d(0, 0, 0), new Vector3d(1, 0, 0), new Vector3d(0, 1, 0));
                                Plane target0 = new Plane(origin0);
                                AllOrientPlanes.Add(origin0, pth.AppendElement(0));
                                AllOrientPlanes.Add(target0, pth.AppendElement(0));

                                // orient crv1
                                Vector3d vect0 = crv1.TangentAtStart;
                                Vector3d vect1 = Vector3d.CrossProduct(vect0, new Vector3d(0.0, 0.0, 1.0));
                                Plane origin1 = new Plane(crv1.PointAtStart, vect0, vect1);

                                Vector3d vect2 = new Vector3d();
                                Vector3d vect3 = new Vector3d();
                                Plane target1 = new Plane();

                                if (Switch == true)
                                {
                                    vect2 = crv0.TangentAtStart;
                                    vect3 = Vector3d.CrossProduct(vect2, new Vector3d(0.0, 0.0, 1.0));
                                    target1 = new Plane(crv0.PointAtStart, vect2, vect3);
                                }

                                else
                                {
                                    vect2 = crv0.TangentAtStart;
                                    vect3 = Vector3d.CrossProduct(-vect2, new Vector3d(0.0, 0.0, 1.0));
                                    target1 = new Plane(crv0.PointAtEnd, -vect2, vect3);
                                }

                                AllOrientPlanes.Add(origin1, pth.AppendElement(1));
                                AllOrientPlanes.Add(target1, pth.AppendElement(1));
                                // shared curve of stripe0 and stripe 1
                                AllSharedCurves.Add(crv0, pth.AppendElement(0));
                                AllSharedCurves.Add(crv1, pth.AppendElement(0));

                            }
                        }

                        // orient crv2
                        foreach (Curve crv2 in ForReorientBreps.Branch(i)[2].Curves3D)
                        {
                            double l0 = crv0.GetLength();
                            double l1 = crv2.GetLength();

                            if (Math.Abs(l0 - l1) < 0.00001)
                            {
                                Vector3d vect0 = crv2.TangentAtStart;
                                Vector3d vect1 = Vector3d.CrossProduct(vect0, new Vector3d(0.0, 0.0, 1.0));
                                Plane origin2 = new Plane(crv2.PointAtStart, vect0, vect1);

                                Vector3d vect2 = new Vector3d();
                                Vector3d vect3 = new Vector3d();
                                Plane target2 = new Plane();

                                if (Switch == true)
                                {
                                    vect2 = crv0.TangentAtStart;
                                    vect3 = Vector3d.CrossProduct(vect2, new Vector3d(0.0, 0.0, 1.0));
                                    target2 = new Plane(crv0.PointAtStart, vect2, vect3);
                                }

                                else
                                {
                                    vect2 = crv0.TangentAtStart;
                                    vect3 = Vector3d.CrossProduct(-vect2, new Vector3d(0.0, 0.0, 1.0));
                                    target2 = new Plane(crv0.PointAtEnd, -vect2, vect3);
                                }

                                AllOrientPlanes.Add(origin2, pth.AppendElement(2));
                                AllOrientPlanes.Add(target2, pth.AppendElement(2));
                                // shared curve of stripe0 and stripe 2
                                AllSharedCurves.Add(crv2, pth.AppendElement(2));
                                AllSharedCurves.Add(crv0, pth.AppendElement(2));
                            }
                        }

                    }
                    // find the shared curve oft stripe 1 and stripe 2
                    foreach (Curve crv1 in ForReorientBreps.Branch(i)[1].Curves3D)
                    {
                        foreach (Curve crv2 in ForReorientBreps.Branch(i)[2].Curves3D)
                        {
                            double l1 = crv1.GetLength();
                            double l2 = crv2.GetLength();

                            // shared curve of stripe1 and stripe 2
                            if (Math.Abs(l1 - l2) < 0.00001)
                            {
                                AllSharedCurves.Add(crv1, pth.AppendElement(1));
                                AllSharedCurves.Add(crv2, pth.AppendElement(1));
                            }

                        }

                    }
                }

            }

            //---- End Functions --------------------------------------------------------------------------
            //----Set Output-------------------------------------------------------------------------------

            DA.SetDataTree(0, AllUnrolledBreps);
            DA.SetDataTree(1, AllOrientPlanes);
            DA.SetDataTree(2, AllSharedCurves);
            DA.SetDataTree(3, AllUnrolledPoints);

            //----End Set Output---------------------------------------------------------------------------
        }
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            //----Declareing--------------------------------------------------------------------------

            // contains the 3 points of each face
            DataTree<Point3f> facePoints = new DataTree<Point3f>();
            // contains the coresponding topology points of each face
            DataTree<int> faceTopologyPoints = new DataTree<int>();
            // contains the face normals of each face
            List<Vector3f> faceNormals = new List<Vector3f>();

            // contains the 3 topology edges of each face
            DataTree<int> faceTopoEdgesIdx = new DataTree<int>();
            // contains the points of each topology edge
            DataTree<int> topologyEdgesTopPtsIdx = new DataTree<int>();

            // Contains the coordinates of each topology point
            List<Point3d> topologyPoints = new List<Point3d>();
            // Contains the index of neighbouring faces for each face
            DataTree<int> faceNeighbours = new DataTree<int>();
            // Contains Normals of topology vertices
            List<Vector3d> topologyNormals = new List<Vector3d>();

            // Contains the index of topology Edges for each Topology Point
            DataTree<int> TopPt_Connected_TopEdges = new DataTree<int>();

            //get Mesh from input
            Mesh M = new Mesh();
            DA.GetData<Mesh>("Mesh", ref M);

            //----End Declareing-----------------------------------------------------------------------

            //----Functions------------------------------------------------------------------------------

            // get List with sublist of 3 points per face
            for (int face_id = 0; face_id < M.Faces.Count; face_id++)
            {
                // set up the branch index
                GH_Path pth = new GH_Path(face_id);

                # region FacePoints

                //---- Face Points (Point3f)
                Point3f A, B, C, D;
                M.Faces.GetFaceVertices(face_id, out A, out B, out C, out D);

                facePoints.Add(A, pth);
                facePoints.Add(B, pth);
                facePoints.Add(C, pth);

                #endregion FacePoints

                #region FaceNormals
                //---- Face Normals (Vector3f)
                M.FaceNormals.ComputeFaceNormals();
                faceNormals.Add(M.FaceNormals[face_id]);
                #endregion FaceNormals

                #region faceTopologyPoints

                //---- Topology Points of the face (int)
                int TA = M.Faces.GetTopologicalVertices(face_id)[0];
                int TB = M.Faces.GetTopologicalVertices(face_id)[1];
                int TC = M.Faces.GetTopologicalVertices(face_id)[2];

                faceTopologyPoints.Add(TA, pth);
                faceTopologyPoints.Add(TB, pth);
                faceTopologyPoints.Add(TC, pth);

                #endregion faceTopologyPoints

                #region faceNeighbours

                //---- Neighbours of face (int)

                foreach (int i in M.TopologyEdges.GetEdgesForFace(face_id))
                {
                    if (M.TopologyEdges.GetConnectedFaces(i).Length > 1)
                    {
                        foreach (int j in M.TopologyEdges.GetConnectedFaces(i))
                        {
                            if (j != face_id)
                            { faceNeighbours.Add(j, pth); }
                        }
                    }
                    else
                    { faceNeighbours.Add(-1, pth); }
                }

                #endregion faceNeighbours

                #region Face Topology Edges

                //---- Topology Edges (int)

                foreach (int i in M.TopologyEdges.GetEdgesForFace(face_id))
                { faceTopoEdgesIdx.Add(i, pth); }

                #endregion Face Topology Edges

            }

            for (int i = 0; i < M.TopologyVertices.Count; i++)
            {
                #region topologyPoints
                //---- Topology Points (point3f)
                int[] vertIdx = M.TopologyVertices.MeshVertexIndices(i);
                topologyPoints.Add(M.Vertices[vertIdx[0]]);
                #endregion topologyPoints

                #region topologyNormals
                //---- Topology Normals
                M.FaceNormals.ComputeFaceNormals();
                Vector3d normal = new Vector3d(0, 0, 0);
                int count = 0;

                foreach (int face in M.TopologyVertices.ConnectedFaces(i))
                {
                    Vector3f temp = new Vector3f();
                    temp = M.FaceNormals[face];
                    Vector3d temp2 = new Vector3d(temp.X, temp.Y, temp.Z);
                    normal += temp2;
                    count++;
                }

                normal /= count;
                topologyNormals.Add(normal);
                #endregion topologyNormals

            }

            #region Topology Edges

            for (int i = 0; i < M.TopologyEdges.Count; i++)
            {
                topologyEdgesTopPtsIdx.Add(M.TopologyEdges.GetTopologyVertices(i).I, new GH_Path(i));
                topologyEdgesTopPtsIdx.Add(M.TopologyEdges.GetTopologyVertices(i).J, new GH_Path(i));
            }

            #endregion Topology Edges

            #region Topology Vertex connected Topology Edge

            for (int i = 0; i < topologyPoints.Count; i++)
            {
                // i = index of Topology Point
                GH_Path pth = new GH_Path(i);

                for (int j = 0; j < topologyEdgesTopPtsIdx.BranchCount; j++)
                {
                    // j = index of Topology Edge
                    foreach (int k in topologyEdgesTopPtsIdx.Branch(j))
                    {
                        if (k == i)
                        // add multiple Topology Edges to the branch index, which is representing the topology point index
                        { TopPt_Connected_TopEdges.Add(j, pth); }
                    }
                }
            }

            #endregion Topology Vertex connected Topology Edge

            //----End Functions--------------------------------------------------------------------------

            //----Set Output-----------------------------------------------------------------------------

            DA.SetDataTree(0, facePoints);
            DA.SetDataTree(1, faceTopologyPoints);
            DA.SetDataList(2, faceNormals);
            DA.SetDataTree(3, faceNeighbours);
            DA.SetDataList(4, topologyPoints);
            DA.SetDataList(5, topologyNormals);
            DA.SetDataTree(6, faceTopoEdgesIdx);
            DA.SetDataTree(7, topologyEdgesTopPtsIdx);
            DA.SetDataTree(8, TopPt_Connected_TopEdges);

            //----End Set Output-------------------------------------------------------------------------
        }
예제 #33
0
        private Mesh local_tet(Plane pl, double xBase, double yBase, double zBase)
        {
            List<Point3d> list = new List<Point3d> {
              pl.PointAt(-xBase, yBase, -zBase),
              pl.PointAt(xBase, yBase, -zBase),
              pl.PointAt(xBase, -yBase, -zBase),
              pl.PointAt(-xBase, -yBase, -zBase),
              pl.PointAt(-xBase, yBase, zBase),
              pl.PointAt(xBase, yBase, zBase),
              pl.PointAt(xBase, -yBase, zBase),
              pl.PointAt(-xBase, -yBase, zBase)
              };

            List<double> list2 = new List<double>();
            foreach (Point3d pointd in list)
            {
                double item = this.calculate_field(pointd);
                list2.Add(item);
            }
            DataTree<Point3d> tree = new DataTree<Point3d>();
            Point3d[] data = new Point3d[] { list[0], list[2], list[3], list[7] };
            tree.AddRange(data, new GH_Path(0));
            data = new Point3d[] { list[0], list[2], list[6], list[7] };
            tree.AddRange(data, new GH_Path(1));
            data = new Point3d[] { list[0], list[4], list[6], list[7] };
            tree.AddRange(data, new GH_Path(2));
            data = new Point3d[] { list[0], list[6], list[1], list[2] };
            tree.AddRange(data, new GH_Path(3));
            data = new Point3d[] { list[0], list[6], list[1], list[4] };
            tree.AddRange(data, new GH_Path(4));
            data = new Point3d[] { list[5], list[6], list[1], list[4] };
            tree.AddRange(data, new GH_Path(5));
            DataTree<double> tree2 = new DataTree<double>();
            tree2.AddRange(new double[] { list2[0], list2[2], list2[3], list2[7] }, new GH_Path(0));
            tree2.AddRange(new double[] { list2[0], list2[2], list2[6], list2[7] }, new GH_Path(1));
            tree2.AddRange(new double[] { list2[0], list2[4], list2[6], list2[7] }, new GH_Path(2));
            tree2.AddRange(new double[] { list2[0], list2[6], list2[1], list2[2] }, new GH_Path(3));
            tree2.AddRange(new double[] { list2[0], list2[6], list2[1], list2[4] }, new GH_Path(4));
            tree2.AddRange(new double[] { list2[5], list2[6], list2[1], list2[4] }, new GH_Path(5));
            Mesh mesh = new Mesh();
            foreach (GH_Path path in tree2.Paths)
            {
                List<Point3d> list3 = tree.Branch(path);
                List<double> list4 = tree2.Branch(path);
                int num2 = 0;
                if (list4[0] < this.use_iso)
                {
                    num2 |= 1;
                }
                if (list4[1] < this.use_iso)
                {
                    num2 |= 2;
                }
                if (list4[2] < this.use_iso)
                {
                    num2 |= 4;
                }
                if (list4[3] < this.use_iso)
                {
                    num2 |= 8;
                }
                Mesh other = new Mesh();
                switch (num2)
                {
                    case 1:
                    case 14:
                        other.Vertices.Add(this.interp_vertex(list3[0], list3[1], list4[0], list4[1]));
                        other.Vertices.Add(this.interp_vertex(list3[0], list3[2], list4[0], list4[2]));
                        other.Vertices.Add(this.interp_vertex(list3[0], list3[3], list4[0], list4[3]));
                        other.Faces.AddFace(0, 1, 2);
                        break;

                    case 2:
                    case 13:
                        other.Vertices.Add(this.interp_vertex(list3[1], list3[0], list4[1], list4[0]));
                        other.Vertices.Add(this.interp_vertex(list3[1], list3[3], list4[1], list4[3]));
                        other.Vertices.Add(this.interp_vertex(list3[1], list3[2], list4[1], list4[2]));
                        other.Faces.AddFace(0, 1, 2);
                        break;

                    case 3:
                    case 12:
                        other.Vertices.Add(this.interp_vertex(list3[0], list3[3], list4[0], list4[3]));
                        other.Vertices.Add(this.interp_vertex(list3[0], list3[2], list4[0], list4[2]));
                        other.Vertices.Add(this.interp_vertex(list3[1], list3[3], list4[1], list4[3]));
                        other.Faces.AddFace(0, 1, 2);
                        other.Vertices.Add(this.interp_vertex(list3[1], list3[2], list4[1], list4[2]));
                        other.Faces.AddFace(2, 3, 1);
                        break;

                    case 4:
                    case 11:
                        other.Vertices.Add(this.interp_vertex(list3[2], list3[0], list4[2], list4[0]));
                        other.Vertices.Add(this.interp_vertex(list3[2], list3[1], list4[2], list4[1]));
                        other.Vertices.Add(this.interp_vertex(list3[2], list3[3], list4[2], list4[3]));
                        other.Faces.AddFace(0, 1, 2);
                        break;

                    case 5:
                    case 10:
                        other.Vertices.Add(this.interp_vertex(list3[0], list3[1], list4[0], list4[1]));
                        other.Vertices.Add(this.interp_vertex(list3[2], list3[3], list4[2], list4[3]));
                        other.Vertices.Add(this.interp_vertex(list3[0], list3[3], list4[0], list4[3]));
                        other.Faces.AddFace(0, 1, 2);
                        other.Vertices.Add(this.interp_vertex(list3[1], list3[2], list4[1], list4[2]));
                        other.Faces.AddFace(0, 3, 1);
                        break;

                    case 6:
                    case 9:
                        other.Vertices.Add(this.interp_vertex(list3[0], list3[1], list4[0], list4[1]));
                        other.Vertices.Add(this.interp_vertex(list3[1], list3[3], list4[1], list4[3]));
                        other.Vertices.Add(this.interp_vertex(list3[2], list3[3], list4[2], list4[3]));
                        other.Faces.AddFace(0, 1, 2);
                        other.Vertices.Add(this.interp_vertex(list3[0], list3[2], list4[0], list4[2]));
                        other.Faces.AddFace(0, 3, 2);
                        break;

                    case 7:
                    case 8:
                        other.Vertices.Add(this.interp_vertex(list3[3], list3[0], list4[3], list4[0]));
                        other.Vertices.Add(this.interp_vertex(list3[3], list3[2], list4[3], list4[2]));
                        other.Vertices.Add(this.interp_vertex(list3[3], list3[1], list4[3], list4[1]));
                        other.Faces.AddFace(0, 1, 2);
                        break;
                }
                mesh.Append(other);
            }
            mesh.Vertices.CombineIdentical(true, true);
            return mesh;
        }
예제 #34
0
        private void RunScript(List<Mesh> x, List<int> y,  List<double>  z, ref object A, ref object B, ref object C,ref object D)
        {
            try
            {
                DataTree<double> output222;
                if (temp.Count == 0)
                {
                    temp = y;
                    for (int i = 0; i < x.Count; i++)
                    {
                        GH_Path path = new GH_Path(i);
                        List<Line> output11;
                        List<double> output22;
                        Point3d output33;
                        List<Point3d> output44;
                        Print(Step(x[i], y[i], 0.5, true, out output11, out output22, out output33, out output44));
                        output1.AddRange(output11, path);
                        output2.AddRange(output22, path);
                        output3.Add(output33, path);
                        output4.AddRange(output44, path);
                    }
                }
                else
                {
                    for (int i = 0; i < y.Count; i++)
                    {
                        GH_Path path = new GH_Path(i);
                        if (y[i] != temp[i])
                        {
                            List<Line> output11;
                            List<double> output22;
                            Point3d output33;
                            List<Point3d> output44;
                            Print(Step(x[i], y[i], 0.5, true, out output11, out output22, out output33, out output44));
                            output1.Branch(path).Clear();
                            output1.Branch(path).AddRange(output11);
                            output2.Branch(path).Clear();
                            output2.Branch(path).AddRange(output22);
                            output3.Branch(path)[0] = output33;
                            output4.Branch(path).Clear();
                            output4.Branch(path).AddRange(output44);
                            temp[i] = y[i];
                        }
                    }
                }

                output222 = new DataTree<double>(output2);
                for (int i = 0; i < output222.Paths.Count; i++)
                {
                    GH_Path path = new GH_Path(i);
                    for(int j=0;j<output222.Branch(path).Count;j++){
                        output222[path, j] *= z[i];
                }}
                A = output1; B = output222; C = output3; D = output4;
            }
            catch (Exception ex)
            {
                Print(ex.ToString());
            }
        }