当前位置: 首页>>代码示例>>C#>>正文


C# IGH_DataAccess.SetDataTree方法代码示例

本文整理汇总了C#中IGH_DataAccess.SetDataTree方法的典型用法代码示例。如果您正苦于以下问题:C# IGH_DataAccess.SetDataTree方法的具体用法?C# IGH_DataAccess.SetDataTree怎么用?C# IGH_DataAccess.SetDataTree使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IGH_DataAccess的用法示例。


在下文中一共展示了IGH_DataAccess.SetDataTree方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: SolveInstance

        protected override void SolveInstance(IGH_DataAccess DA)
        {
            GH_Program program = null;
            DA.GetData(0, ref program);

            var path = DA.ParameterTargetPath(0);
            var cellTargets = program.Value.Targets;
            var groupCount = cellTargets[0].ProgramTargets.Count;

            var planes = new GH_Structure<GH_Plane>();
            var joints = new GH_Structure<GH_Number>();
            var configuration = new GH_Structure<GH_String>();
            var deltaTime = new GH_Structure<GH_Number>();

            for (int i = 0; i < groupCount; i++)
            {
                var tempPath = path.AppendElement(i);
                for (int j = 0; j < cellTargets.Count; j++)
                {
                    planes.AppendRange(cellTargets[j].ProgramTargets[i].Kinematics.Planes.Select(x => new GH_Plane(x)), tempPath.AppendElement(j));
                    joints.AppendRange(cellTargets[j].ProgramTargets[i].Kinematics.Joints.Select(x => new GH_Number(x)), tempPath.AppendElement(j));
                    configuration.Append(new GH_String(cellTargets[j].ProgramTargets[i].Kinematics.Configuration.ToString()), tempPath);
                    deltaTime.Append(new GH_Number(cellTargets[j].DeltaTime), tempPath);
                }
            }

            DA.SetDataTree(0, planes);
            DA.SetDataTree(1, joints);
            DA.SetDataTree(2, configuration);
            DA.SetDataTree(3, deltaTime);
        }
开发者ID:visose,项目名称:Robots,代码行数:31,代码来源:Util.cs

示例2: SolveInstance

        protected override void SolveInstance(IGH_DataAccess DA)
        {
            string name = null; 
            GH_RobotSystem robotSystem = null;
            var initCommandsGH = new List<GH_Command>();
            var targetsA = new List<GH_Target>();
            var targetsB = new List<GH_Target>();
            var multiFileIndices = new List<int>();
            double stepSize = 1;

            if (!DA.GetData(0, ref name)) { return; }
            if (!DA.GetData(1, ref robotSystem)) { return; }
            if (!DA.GetDataList(2, targetsA)) { return; }
            DA.GetDataList(3, targetsB);
            DA.GetDataList(4, initCommandsGH);
            DA.GetDataList(5, multiFileIndices);
            if (!DA.GetData(6, ref stepSize)) { return; }

            var initCommands = initCommandsGH.Count > 0 ? new Robots.Commands.Group(initCommandsGH.Select(x => x.Value)) : null;

            var targets = new List<IEnumerable<Target>>();
            targets.Add(targetsA.Select(x => x.Value));
            if (targetsB.Count > 0) targets.Add(targetsB.Select(x => x.Value));

            var program = new Program(name, robotSystem.Value, targets, initCommands, multiFileIndices, stepSize);

            DA.SetData(0, new GH_Program(program));


            if (program.Code != null)
            {
                var path = DA.ParameterTargetPath(2);
                var structure = new GH_Structure<GH_String>();

                for (int i = 0; i < program.Code.Count; i++)
                {
                    var tempPath = path.AppendElement(i);
                    for (int j = 0; j < program.Code[i].Count; j++)
                    {
                        structure.AppendRange(program.Code[i][j].Select(x => new GH_String(x)), tempPath.AppendElement(j));
                    }
                }

                DA.SetDataTree(1, structure);
            }

            DA.SetData(2, program.Duration);

            if (program.Warnings.Count > 0)
            {
                DA.SetDataList(3, program.Warnings);
                this.AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Warnings in program");
            }

            if (program.Errors.Count > 0)
            {
                DA.SetDataList(4, program.Errors);
                this.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Errors in program");
            }
        }
开发者ID:visose,项目名称:Robots,代码行数:60,代码来源:Program.cs

示例3: SetOutputs

    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);
    }
开发者ID:lxfschr,项目名称:Quelea,代码行数:27,代码来源:GetPositionHistoryComponent.cs

示例4: SolveInstance

        protected override void SolveInstance(IGH_DataAccess DA)
        {
            Mesh mesh = new Mesh();
            double contourBaseZ = 0;
            double contourInterval = 0;

            DA.GetData(0, ref mesh);
            DA.GetData(1, ref contourBaseZ);
            DA.GetData(2, ref contourInterval);

            if (mesh == null) return;

            List<double> contourZList = GetContourZList(mesh, contourBaseZ, contourInterval);
            DataTree<Curve> contourTree = GetContourTree(mesh, contourZList);
            List<Brep> brepList = GetBrepList(mesh, contourZList, contourTree);
            Brep terrainRegion = GetTerrainRegion(mesh);
            DataTree<Object> stepTree = GetStepTree(mesh, contourZList, contourTree, brepList);

            DA.SetDataTree(0, contourTree);
            DA.SetDataTree(1, stepTree);
        }
开发者ID:parkjunseok,项目名称:Beaver,代码行数:21,代码来源:Beaver.Terrain.cs

示例5: SolveInstance

    /// <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)
    {
      // First, we need to retrieve all data from the input parameters.
      // We'll start by declaring variables and assigning them starting values.
      Boolean reset = true;
      bool liveUpdate = true;
      List<T.AgentSystem> systems = new List<T.AgentSystem>();

      // Then we need to access the input parameters individually. 
      // When data cannot be extracted from a parameter, we should abort this method.
      if (!DA.GetData(0, ref reset)) return;
      if (!DA.GetData(1, ref liveUpdate)) return;
      if (!DA.GetDataList(2, systems)) return;

      // We should now validate the data and warn the user if invalid data is supplied.

      // We're set to create the output now. To keep the size of the SolveInstance() method small, 
      // The actual functionality will be in a different method:
      DataTree<AgentType> agents = run(reset, liveUpdate, systems);
      //List<Point3d> agents = new List<Point3d>();

      // Finally assign the spiral to the output parameter.
      DA.SetDataTree(0, agents);
    }
开发者ID:lxfschr,项目名称:Quelea,代码行数:28,代码来源:EngineComponent.cs

示例6: SolveInstance


//.........这里部分代码省略.........
            List<string> metaData = new List<string>();
            GH_Structure<GH_String> values = new GH_Structure<GH_String>();
            GH_Structure<GH_String> addresses = new GH_Structure<GH_String>();

            //get data from inputs
            if (!DA.GetData<AuthToken>("Token", ref authToken))
            {
                return; //exit if no token
            }
            if (!authToken.IsValid)
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "The provided authentication token appears to be invalid. Try re-running the Google Authenticator component.");
                return; //exit if invalid token
            }

            if (!DA.GetData<string>("Name", ref sheetName))
            {
                return; //exit if no name provided
            }
            DA.GetData<string>("Worksheet", ref worksheet);
            DA.GetData<bool>("Include Blank Cells?", ref includeBlankCells);
            if (DA.GetData<SpreadsheetRange>("Spreadsheet Range", ref range))
            {
                rangeSpecified = true;
            }
            DA.GetData<bool>("Organize by Rows or Columns", ref rowsColumns);
            DA.GetData<bool>("Read Formulas or Values", ref formulasValues);

            //set up oAuth parameters
            OAuth2Parameters parameters = GDriveUtil.GetParameters(authToken);
            //establish spreadsheetservice
            SpreadsheetsService service = GDriveUtil.GetSpreadsheetsService(parameters);
            //get spreadsheet by name
            SpreadsheetEntry spreadsheet = GDriveUtil.findSpreadsheetByName(sheetName, service);

            if (spreadsheet == null)
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Specified Spreadsheet not found.");
                return;
            }

            //gather spreadsheet metadata
            metaData.Add("Spreadsheet Name: " + spreadsheet.Title.Text);
            metaData.Add("Last Updated: " + spreadsheet.Updated.ToString());
            metaData.Add("Worksheets: " + worksheetList(spreadsheet.Worksheets));

            //find the specified worksheet, or first one if none specified
            WorksheetEntry worksheetEntry = null;
            worksheetEntry = GDriveUtil.findWorksheetByName(worksheet, spreadsheet);

            if (worksheetEntry == null)
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Specified worksheet not found.");
                return;
            }

            // Fetch the cell feed of the worksheet.
            CellQuery cellQuery = new CellQuery(worksheetEntry.CellFeedLink);
            if (rangeSpecified)
            {
                if (range.TestValid())
                {
                    cellQuery.MinimumColumn = range.startColumn();
                    cellQuery.MinimumRow = range.startRow();
                    cellQuery.MaximumColumn = range.endColumn();
                    cellQuery.MaximumRow = range.endRow();
                }
                else
                {
                    AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Invalid Range Specified");
                    return;
                }
            }

            //passes null values if user wants the blank cells represented, otherwise they are omitted from output.
            if (includeBlankCells)
            {
                cellQuery.ReturnEmpty = ReturnEmptyCells.yes;
            }
            //set up cell feed
            CellFeed cellFeed = service.Query(cellQuery);

            foreach (CellEntry cell in cellFeed.Entries) //for all the cells in the feed
            {

                GH_Path path = new GH_Path(DA.Iteration); //set up data path for data tree
                uint e = (rowsColumns) ? cell.Row : cell.Column; //decide whether to structure data path by row or column
                path = path.AppendElement((int)e);

                string v = (formulasValues) ? cell.InputValue : cell.Value; //decide whether to get the cell formula or the cell value as output
                values.Append(new GH_String(v), path); //save the value of the cell

                addresses.Append(new GH_String(cell.Title.Text), path); // save the address of the cell
            }

            //set output data
            DA.SetDataTree(0, values);
            DA.SetDataTree(1, addresses);
            DA.SetDataList("Sheet Info", metaData);
        }
开发者ID:ptierney,项目名称:leafcutter,代码行数:101,代码来源:ReadSpreadsheet.cs

示例7: SetOutputs

 protected override void SetOutputs(IGH_DataAccess da)
 {
   AbstractEnvironmentType environment = new PolysurfaceEnvironmentType(brep, borderDir);
   da.SetData(nextOutputIndex++, environment);
   da.SetDataTree(nextOutputIndex++, BrepArray2DToDatatree(((PolysurfaceEnvironmentType)environment).BorderWallsArray));
 }
开发者ID:lxfschr,项目名称:Quelea,代码行数:6,代码来源:PolysurfaceEnvironmentComponent.cs

示例8: SolveInstance


//.........这里部分代码省略.........
            DataTree<Brep> SofistikBreps = new DataTree<Brep>();
            DataTree<int> SofistikBrepsIdx = new DataTree<int>();

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

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

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

            int componentIdx = 0;

            foreach (Tri_Loop_Component component in All_Components)
            {
                GH_Path pth1 = new GH_Path(componentIdx);

                // run / generate Informations for Sofistik
                component.SofistikInformation();
                component.SofistikCreateSurfaces();

                // Points
                for (int j = 0; j < component.SofistikPlatePoints.BranchCount; j++)
                {

                    foreach (Point3d p in component.SofistikPlatePoints.Branch(j))
                    { SofistikPoints.Add(p, pth1.AppendElement(j)); }

                    foreach (int idx in component.SofistikPlateIndexies.Branch(j))
                    { SofistikIndexies.Add(idx, pth1.AppendElement(j)); }
                }

                // CurvePoints
                for (int j = 0; j < component.SofistikCrvPtCoo.BranchCount; j++)
                {
                    GH_Path pth0 = component.SofistikCrvPtCoo.Path(j);

                    foreach (Point3d pt in component.SofistikCrvPtCoo.Branch(j))
                    {
                        //pth1.AppendElement(pth0[0]);
                        //pth1.AppendElement(pth0[1]);
                        //SofistikCrvPtCoo.Add(pt, pth1.AppendElement(pth0[0]));

                        // 2 level Tree
                        SofistikCrvPtCoo.Add(pt, pth1.AppendElement(pth0[0]));

                    }

                    foreach (int idx in component.SofistikCrvPtIdx.Branch(j))
                    {
                        //pth1.AppendElement(pth0[0]);
                        //pth1.AppendElement(pth0[1]);
                        //SofistikCrvPtIdx.Add(idx, pth1.AppendElement(pth0[0]));

                        // 2 level Tree
                        SofistikCrvPtIdx.Add(idx, pth1.AppendElement(pth0[0]));

                    }
                }

                // Curves
                for (int i = 0; i < component.SofistikCurves.BranchCount; i++)
                {
                    GH_Path pth0 = component.SofistikCurves.Path(i);

                    foreach (Curve c in component.SofistikCurves.Branch(i))
                    {
                        SofistikCurves.Add(c, pth1.AppendElement(pth0[0]));
                    }

                }

                // Surfaces
                for (int j = 0; j < component.SofistikSurfaces.BranchCount; j++)
                {

                    foreach (Brep[] p in component.SofistikSurfaces.Branch(j))
                    { SofistikBreps.Add(p[0], pth1.AppendElement(j)); }

                    foreach (int idx in component.SofistikSurfacesIdx.Branch(j))
                    { SofistikBrepsIdx.Add(idx, pth1.AppendElement(j)); }
                }

                componentIdx++;
            }

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

            DA.SetDataTree(0, SofistikPoints);
            DA.SetDataTree(1, SofistikIndexies);

            DA.SetDataTree(2, SofistikCrvPtCoo);
            DA.SetDataTree(3, SofistikCrvPtIdx);

            DA.SetDataTree(4, SofistikBreps);
            DA.SetDataTree(5, SofistikBrepsIdx);

            DA.SetDataTree(6, SofistikCurves);

            //---- End Set Output -----------------------------------------------------------------------
        }
开发者ID:GeneKao,项目名称:Pavilion2015_ITECH,代码行数:101,代码来源:GHC_03_Sofistik.cs

示例9: SolveInstance

        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object can be used to retrieve data from input parameters and 
        /// to store data in output parameters.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            ////////////////////////
            //  Retrieve crucial (fixed) input data, exit if non-existent
            ////////////////////////

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

            ////////////////////////
            // check if cluster was properly loaded, and if parameters are correct
            // and if not, do something about it!
            ////////////////////////

            if (loadedClusterUrlParam == null ||
                loadedClusterUrlParam != clusterUrlParam)
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Cluster not loaded properly - click on 'Reload Cluster' button!");
            //                MessageBox.Show("hey, don't we have a parameter mismatch?");
                //we've got a parameter mismatch
                // urge user to click on buttom to match paramcount to cluster param count
            /*                (this.m_attributes as Attributes_Custom).button.Palette = GH_Palette.Pink;
                (this.m_attributes as Attributes_Custom).ExpireLayout();
                (this.m_attributes as Attributes_Custom).PerformLayout();
                NEXT STEP - HIGHLIGHT BUTTON */

            }
            else
            {
                //successful! parameters match. so - let's run this thing:

                //get data from hairworm inputs, put into array
                for (int i = fixedParamNumInput; i < (fixedParamNumInput + clusterParamNumInput); i++)
                {
                    if (!DA.GetDataList(i, clusterInputLists[i - fixedParamNumInput])) { return; }
                    //if (!DA.GetData(i, ref clusterInput[i - fixedParamNumInput])) { return; }
            //                    debugText += "okay, input # " + i + " is: " + clusterInputs[i - fixedParamNumInput].ToString() + "\n";
            //					DA.SetData(0, debugText);
                }

                // get data from array, input into cluster
                for (int i = fixedParamNumInput; i < (fixedParamNumInput + clusterParamNumInput); i++)
                {
            //                    wormCluster.Params.Input[i - fixedParamNumInput].AddVolatileData(new GH_Path(0), 0, clusterInputs[i - fixedParamNumInput]);
                    wormCluster.Params.Input[i - fixedParamNumInput].AddVolatileDataList(new GH_Path(0), clusterInputLists[i - fixedParamNumInput]);

                }

                // RUN CLUSTER AND RECOMPUTE THIS
                wormCluster.ExpireSolution(true);

                // get computed data from cluster outputs, push into hairworm outputs
                for (int i = fixedParamNumOutput; i < (fixedParamNumOutput + clusterParamNumOutput); i++)
                {
                    // Create a copy of this data (the original data will be wiped)
                    DataTree<object> copy = new DataTree<object>();
                    copy.MergeStructure(wormCluster.Params.Output[i - fixedParamNumOutput].VolatileData, new Grasshopper.Kernel.Parameters.Hints.GH_NullHint());

                    // push into hairworm component outputs
                    DA.SetDataTree(i, copy);
                }

                DA.SetData(0, debugText);

            }

            DA.SetData(0, debugText);
        }
开发者ID:provolot,项目名称:GrasshopperExchange,代码行数:72,代码来源:HairwormComponent.cs

示例10: SetOutputs

 protected override void SetOutputs(IGH_DataAccess da)
 {
     da.SetDataTree(0, prop);
 }
开发者ID:maajor,项目名称:Physarealm,代码行数:4,代码来源:PopulationPropertyComponent.cs

示例11: SolveInstance


//.........这里部分代码省略.........
            if (spreadsheet == null) //if the spreadsheet is not found
            {
                if (createNewSpreadsheets) //if the user has elected to create new spreadsheets
                {
                   List<string> worksheets = new List<string>();
                   if (!String.IsNullOrEmpty(worksheet))
                   {
                       worksheets.Add(worksheet); //create a 1-item list with the worksheet name
                   }
                    spreadsheet = CreateSpreadsheet.createNewSpreadsheet(this, authToken, sheetName, worksheets, false); //create the spreadsheet
                }
                else
                {
                    AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Specified spreadsheet not found.");
                    return;
                }
            }
            //find worksheet by name
            WorksheetEntry worksheetEntry = GDriveUtil.findWorksheetByName(worksheet, spreadsheet);
            if (worksheetEntry == null)
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Specified worksheet not found.");
                return;
            }

            uint maxRow = 0;
            uint maxCol = 0;
            // set up dictionary<Cell address, cell input>
            // associate each input value with a corresponding address
            Dictionary<string, string> writeMap = constructWriteMap(addresses, data, rowsColumns, ref maxRow, ref maxCol, ref addressesOut);

                //expand worksheet if necessary
                if (worksheetEntry.Rows < maxRow)
                {

                        worksheetEntry.Rows = maxRow;
                        worksheetEntry.Etag = "*"; //required for compatibility with "new" google sheets (see:  http://stackoverflow.com/questions/22719170/updating-cell-in-google-spreadsheets-returns-error-missing-resource-version-id)
                        worksheetEntry.Update();

                }

                if (worksheetEntry.Cols < maxCol)
                {

                        worksheetEntry.Cols = maxCol;
                        worksheetEntry.Etag = "*"; //required for compatibility with "new" google sheets (see:  http://stackoverflow.com/questions/22719170/updating-cell-in-google-spreadsheets-returns-error-missing-resource-version-id)
                        worksheetEntry.Update();

                }

                //set bounds of cell query
                CellQuery cellQuery = new CellQuery(worksheetEntry.CellFeedLink);
                cellQuery.MinimumColumn = 0;
                cellQuery.MinimumRow = 0;
                cellQuery.MaximumColumn = maxCol;
                cellQuery.MaximumRow = maxRow;
                cellQuery.ReturnEmpty = ReturnEmptyCells.yes;

                //retrieve cellfeed
                CellFeed cellFeed = service.Query(cellQuery);

                //convert cell entries to dictionary
               Dictionary<string,AtomEntry> cellDict = cellFeed.Entries.ToDictionary(k => k.Title.Text);

                CellFeed batchRequest = new CellFeed(cellQuery.Uri, service);

                //set up batchrequest
                foreach (KeyValuePair<string, string> entry in writeMap)
                {
                    AtomEntry atomEntry;
                    cellDict.TryGetValue(entry.Key, out atomEntry);
                    CellEntry batchEntry = atomEntry as CellEntry;
                    batchEntry.InputValue = entry.Value;
                    batchEntry.Etag = "*"; //required for compatibility with "new" google sheets (see:  http://stackoverflow.com/questions/22719170/updating-cell-in-google-spreadsheets-returns-error-missing-resource-version-id)
                    batchEntry.BatchData = new GDataBatchEntryData(GDataBatchOperationType.update);

                    batchRequest.Entries.Add(batchEntry);
                }
                CellFeed batchResponse = (CellFeed)service.Batch(batchRequest, new Uri(cellFeed.Batch));

                // Check the results
                bool isSuccess = true;
                foreach (CellEntry entry in batchResponse.Entries)
                {
                    string batchId = entry.BatchData.Id;
                    if (entry.BatchData.Status.Code != 200)
                    {
                        isSuccess = false;
                        GDataBatchStatus status = entry.BatchData.Status;
                    }
                }

                if (!isSuccess)
                {
                    AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Update operations failed");
                }

            //output addresses
            DA.SetDataTree(0, addressesOut); //write addressesOut to first output parameter
        }
开发者ID:ptierney,项目名称:leafcutter,代码行数:101,代码来源:WriteToSpreadsheet.cs

示例12: SolveInstance

        protected override void SolveInstance(IGH_DataAccess DA)
        {
            List<DHr> hours = new List<DHr>();
            String key_r = "";
            String key_a = "";
            if (DA.GetDataList(0, hours) && DA.GetData(1, ref key_r) && DA.GetData(2, ref key_a)) {

                Interval ival_r = new Interval();
                Interval ival_a = new Interval();
                float[] vals_r = new float[0];
                float[] vals_a = new float[0];

                if (!(DA.GetData(3, ref ival_r))) DHr.get_domain(key_r, hours.ToArray(), ref vals_r, ref ival_r);
                else {
                    ival_r = new Interval(hours[0].val(key_r), hours[0].val(key_r));

                    vals_r = new float[hours.Count];
                    for (int h = 0; h < hours.Count; h++) {
                        vals_r[h] = hours[h].val(key_r);
                        if (vals_r[h] < ival_r.T0) ival_r.T0 = vals_r[h];
                        if (vals_r[h] > ival_r.T1) ival_r.T1 = vals_r[h];
                    }
                }

                DHr.get_domain(key_a, hours.ToArray(), ref vals_a, ref ival_a);
                DA.GetData(4, ref ival_a);

                Plane plane = new Plane(new Point3d(0, 0, 0), new Vector3d(0, 0, 1));
                DA.GetData(5, ref plane);

                Interval ival_gr = new Interval();
                Interval ival_ga = new Interval(0, Math.PI * 2);
                DA.GetData(6, ref ival_gr);

                Interval subdivs = new Interval();
                DA.GetData(7, ref subdivs);
                int subdivs_r = (int)Math.Floor(subdivs.T0);
                int subdivs_a = (int)Math.Floor(subdivs.T1);

                List<Point3d> points = new List<Point3d>();
                for (int h = 0; h < hours.Count; h++) {
                    double radius = ival_gr.ParameterAt(ival_r.NormalizedParameterAt(vals_r[h]));
                    double theta = ival_a.NormalizedParameterAt(vals_a[h]) * Math.PI * 2;
                    Point3d gpt = PointByCylCoords(radius, theta); // a point in graph coordinates
                    hours[h].pos = gpt; // the hour records the point in graph coordinates

                    Point3d wpt = plane.PointAt(gpt.X, gpt.Y);
                    points.Add(wpt);  // adds this point in world coordinates
                }

                Grasshopper.Kernel.Data.GH_Structure<Grasshopper.Kernel.Types.GH_Curve> regions = new Grasshopper.Kernel.Data.GH_Structure<Grasshopper.Kernel.Types.GH_Curve>();

                int segments_in_whole_circle = 36;
                //double step_r = ival_r.Length / subdivs_r;
                //double step_a = Math.PI*2 / subdivs_a;

                for (int r = 0; r < subdivs_r; r++)
                    for (int a = 0; a < subdivs_a; a++) {
                        Interval rad = new Interval(ival_gr.ParameterAt(r / (float)subdivs_r), ival_gr.ParameterAt((r + 1) / (float)subdivs_r));
                        Interval ang = new Interval(ival_ga.ParameterAt(a / (float)subdivs_a), ival_ga.ParameterAt((a + 1) / (float)subdivs_a));

                        int cnt = (int)Math.Ceiling(segments_in_whole_circle * ang.Length / Math.PI * 2);
                        Polyline pcrv = new Polyline();
                        pcrv.AddRange(FakeArc(plane, rad.T0, ang.T0, ang.T1, cnt));
                        pcrv.AddRange(FakeArc(plane, rad.T1, ang.T1, ang.T0, cnt));
                        pcrv.Add(pcrv[0]);

                        Grasshopper.Kernel.Types.GH_Curve gh_curve = new Grasshopper.Kernel.Types.GH_Curve();
                        Grasshopper.Kernel.GH_Convert.ToGHCurve(pcrv, GH_Conversion.Both, ref gh_curve);
                        regions.Append(gh_curve, new Grasshopper.Kernel.Data.GH_Path(new int[] { r, a }));
                    }

                DA.SetDataList(0, hours);
                DA.SetDataList(1, points);
                DA.SetDataTree(2, regions);

            }
        }
开发者ID:ksteinfe,项目名称:dyear,代码行数:78,代码来源:Components+Spatializing.cs

示例13: SolveInstance

        protected override void SolveInstance(IGH_DataAccess DA)
        {
            AWorld refwrld = new AWorld();
            List<object> v_list = new List<object>();
            GH_ObjectWrapper gh_dict = new GH_ObjectWrapper();
            IDictionary<string, string> dict = new Dictionary<string,string>();
            string k = "";

            //GH_Dict test = GH_Dict.create("a", 1.0);

            //if (!DA.GetData(0, ref refwrld) || !refwrld.IsValid) return;
            //AWorld wrld = new AWorld(refwrld);

            SpatialGraph gph = new SpatialGraph();
            if (!DA.GetData(0, ref gph)) return;

            int nGen = 0;
            string pyString = "";
            if (!DA.GetData(1, ref pyString)) return;
            if (!DA.GetDataList(2, v_list)) return;
            if (!DA.GetData(3, ref nGen)) return;
            if (!DA.GetData(4, ref gh_dict)) return;
            if (!DA.GetData(5, ref k)) return;

            //dict = (IDictionary<string, string>)gh_dict.Value;

            //object d = gh_dict.Value;
            var t = Type.GetType("IronPython.Runtime.PythonDictionary,IronPython");
            IDictionary i_dict = Activator.CreateInstance(t) as IDictionary;
            //IronPython.Runtime.PythonDictionary d = gh_dict.Value;
            //string v = d.get(k);
            string v = "oops";

            // Sets the initial Generation by using the input v_list
            // if it runs out of values, it starts over (wraps)
            //object[] val_list = new object[gph.nodes.Count];
            //int v_i = 0;
            //for (int i = 0; i < gph.nodes.Count; i++)
            //{
            //    if (v_i == v_list.Count) v_i = 0;
            //    val_list[i] = v_list[v_i];
            //    v_i++;
            //}

            //AWorld wrld = new AWorld(gph, val_list);

            //_py = PythonScript.Create();
            //_py.Output = this.m_py_output.Write;
            //_compiled_py = _py.Compile(pyString);

            //// console out
            Grasshopper.Kernel.Data.GH_Structure<Grasshopper.Kernel.Types.GH_String> consoleOut = new Grasshopper.Kernel.Data.GH_Structure<Grasshopper.Kernel.Types.GH_String>();

            //// Main evaluation cycle
            //// Should move code into the Antsworld Class
            //for (int g = 0; g < nGen; g++)
            //{
            //    // console out
            //    this.m_py_output.Reset();

            //    double[] new_vals = new double[wrld.NodeCount];
            //    for (int i = 0; i < wrld.NodeCount; i++)
            //    {
            //        int[] neighboring_indices = wrld.gph.NeighboringIndexesOf(i);

            //        // build list of neighboring values
            //        List<double> neighboring_vals = new List<double>();
            //        for (int k = 0; k < neighboring_indices.Length; k++) neighboring_vals.Add(wrld.LatestGen[neighboring_indices[k]]);

            //        double d = EvaluateCell(i, wrld.LatestGen[i], neighboring_vals);
            //        //double d = g + i + 0.0;

            //        new_vals[i] = d;
            //    }
            //    wrld.AddGen(new_vals);

            //    // console out
            //    Grasshopper.Kernel.Data.GH_Path key_path = new Grasshopper.Kernel.Data.GH_Path(g);
            //    List<Grasshopper.Kernel.Types.GH_String> gh_strs = new List<Grasshopper.Kernel.Types.GH_String>();
            //    foreach (String str in this.m_py_output.Result) gh_strs.Add(new Grasshopper.Kernel.Types.GH_String(str));
            //    consoleOut.AppendRange(gh_strs, key_path);

            //}

            DA.SetDataTree(0, consoleOut);
            //DA.SetData(1, wrld);
            DA.SetData(2, v);
        }
开发者ID:nreifenstein,项目名称:Picnic,代码行数:88,代码来源:AntPicnic.cs

示例14: SolveInstance


//.........这里部分代码省略.........
                    {
                        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-------------------------------------------------------------------------
        }
开发者ID:GeneKao,项目名称:Pavilion2015_ITECH,代码行数:101,代码来源:GHC_01_ConvertMesh.cs

示例15: SolveInstance

        protected override void SolveInstance(IGH_DataAccess DA)
        {
            List<DHr> dhrs = new List<DHr>();
            string period_string = "";
            if ((DA.GetDataList(0, dhrs)) && (DA.GetData(1, ref period_string))) {
                if (period_string == "") { return; }
                period_string = period_string.ToLowerInvariant().Trim();
                this.cycle_type = CType.Invalid;
                if (period_string.Contains("year")) { this.cycle_type = CType.Yearly; } else if (period_string.Contains("monthly diurnal")) { this.cycle_type = CType.MonthlyDiurnal; } else if (period_string.Contains("month")) { this.cycle_type = CType.Monthly; } else if (period_string.Contains("day") || period_string.Contains("daily")) { this.cycle_type = CType.Daily; } else if (period_string.Contains("weekly diurnal")) { this.cycle_type = CType.WeeklyDiurnal; } else if (period_string.Contains("weekly")) { this.cycle_type = CType.Weekly; } else {
                    this.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "I don't understand the time period you're looking for.\nPlease choose 'yearly', 'monthly', 'monthly diurnal', 'weekly', 'weekly diurnal', or 'daily'.");
                }

                string[] commonKeys = DHr.commonkeys(dhrs.ToArray());
                Dictionary<string, List<DHr>> stat_hours = new Dictionary<string, List<DHr>>();
                InitStatHours(ref stat_hours);

                HourMask mask = new HourMask();

                switch (this.cycle_type) {

                    case CType.MonthlyDiurnal:
                    case CType.WeeklyDiurnal:
                        Grasshopper.Kernel.Data.GH_Structure<DHr> meanTree = new Grasshopper.Kernel.Data.GH_Structure<DHr>();
                        Grasshopper.Kernel.Data.GH_Structure<DHr> modeTree = new Grasshopper.Kernel.Data.GH_Structure<DHr>();
                        Grasshopper.Kernel.Data.GH_Structure<DHr> highTree = new Grasshopper.Kernel.Data.GH_Structure<DHr>();
                        Grasshopper.Kernel.Data.GH_Structure<DHr> uqTree = new Grasshopper.Kernel.Data.GH_Structure<DHr>();
                        Grasshopper.Kernel.Data.GH_Structure<DHr> medianTree = new Grasshopper.Kernel.Data.GH_Structure<DHr>();
                        Grasshopper.Kernel.Data.GH_Structure<DHr> lqTree = new Grasshopper.Kernel.Data.GH_Structure<DHr>();
                        Grasshopper.Kernel.Data.GH_Structure<DHr> lowTree = new Grasshopper.Kernel.Data.GH_Structure<DHr>();
                        Grasshopper.Kernel.Data.GH_Structure<DHr> sumTree = new Grasshopper.Kernel.Data.GH_Structure<DHr>();

                        switch (this.cycle_type) {
                            case CType.MonthlyDiurnal:
                                for (int mth = 0; mth < 12; mth++) {
                                    InitStatHours(ref stat_hours);
                                    for (int hour = 0; hour < 24; hour++) {
                                        mask.maskByMonthAndHour(mth, hour);
                                        int hh = Util.hourOfYearFromDatetime(Util.baseDatetime().AddMonths(mth).AddHours(hour)) + 1; // had to add one, looks like Util function was designed for parsing non-zero-indexed hours
                                        CalculateStats(dhrs, commonKeys, stat_hours, mask, hh, true);
                                    }
                                    meanTree.AppendRange(stat_hours["meanHrs"], new Grasshopper.Kernel.Data.GH_Path(mth));
                                    modeTree.AppendRange(stat_hours["modeHrs"], new Grasshopper.Kernel.Data.GH_Path(mth));
                                    highTree.AppendRange(stat_hours["highHrs"], new Grasshopper.Kernel.Data.GH_Path(mth));
                                    uqTree.AppendRange(stat_hours["uqHrs"], new Grasshopper.Kernel.Data.GH_Path(mth));
                                    medianTree.AppendRange(stat_hours["medianHrs"], new Grasshopper.Kernel.Data.GH_Path(mth));
                                    lqTree.AppendRange(stat_hours["lqHrs"], new Grasshopper.Kernel.Data.GH_Path(mth));
                                    lowTree.AppendRange(stat_hours["lowHrs"], new Grasshopper.Kernel.Data.GH_Path(mth));
                                    sumTree.AppendRange(stat_hours["sumHrs"], new Grasshopper.Kernel.Data.GH_Path(mth));
                                }
                                break;
                            case CType.WeeklyDiurnal:
                                for (int wk = 0; wk < 52; wk++) {
                                    InitStatHours(ref stat_hours);
                                    for (int hour = 0; hour < 24; hour++) {
                                        mask.maskByWeekAndHour(wk, hour);
                                        int hh = Util.hourOfYearFromDatetime(Util.baseDatetime().AddDays(wk * 7).AddHours(hour)) + 1; // had to add one, looks like Util function was designed for parsing non-zero-indexed hours
                                        CalculateStats(dhrs, commonKeys, stat_hours, mask, hh, true);
                                    }
                                    meanTree.AppendRange(stat_hours["meanHrs"], new Grasshopper.Kernel.Data.GH_Path(wk));
                                    modeTree.AppendRange(stat_hours["modeHrs"], new Grasshopper.Kernel.Data.GH_Path(wk));
                                    highTree.AppendRange(stat_hours["highHrs"], new Grasshopper.Kernel.Data.GH_Path(wk));
                                    uqTree.AppendRange(stat_hours["uqHrs"], new Grasshopper.Kernel.Data.GH_Path(wk));
                                    medianTree.AppendRange(stat_hours["medianHrs"], new Grasshopper.Kernel.Data.GH_Path(wk));
                                    lqTree.AppendRange(stat_hours["lqHrs"], new Grasshopper.Kernel.Data.GH_Path(wk));
                                    lowTree.AppendRange(stat_hours["lowHrs"], new Grasshopper.Kernel.Data.GH_Path(wk));
                                    sumTree.AppendRange(stat_hours["sumHrs"], new Grasshopper.Kernel.Data.GH_Path(wk));
                                }
                                break;
                        }
                        DA.SetDataTree(0, meanTree);
                        DA.SetDataTree(1, modeTree);
                        DA.SetDataTree(2, highTree);
                        DA.SetDataTree(3, uqTree);
                        DA.SetDataTree(4, medianTree);
                        DA.SetDataTree(5, lqTree);
                        DA.SetDataTree(6, lowTree);
                        DA.SetDataTree(7, sumTree);
                        break;

                    case CType.Daily:
                        for (int day = 0; day < 365; day++) {
                            mask.maskByDayOfYear(day, day); // passing in same day twice masks to this single day
                            int hh = Util.hourOfYearFromDatetime(Util.baseDatetime().AddDays(day).AddHours(0)) + 1; // had to add one, looks like Util function was designed for parsing non-zero-indexed hours
                            CalculateStats(dhrs, commonKeys, stat_hours, mask, hh, true);
                        }
                        SetOutputData(DA, stat_hours);
                        break;

                    case CType.Weekly:
                        for (int wk = 0; wk < 52; wk++) {
                            mask.maskByWeek(wk);
                            int hh = Util.hourOfYearFromDatetime(Util.baseDatetime().AddDays(wk * 7).AddHours(0)) + 1; // had to add one, looks like Util function was designed for parsing non-zero-indexed hours
                            CalculateStats(dhrs, commonKeys, stat_hours, mask, hh, true);
                        }
                        SetOutputData(DA, stat_hours);
                        break;

                    case CType.Monthly:
                        for (int mth = 0; mth < 12; mth++) {
                            mask.maskByMonthOfYear(mth);
//.........这里部分代码省略.........
开发者ID:ksteinfe,项目名称:dyear,代码行数:101,代码来源:Components+Filter.cs


注:本文中的IGH_DataAccess.SetDataTree方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。