Grasshopper

algorithmic modeling for Rhino

I am getting 'An error occured in the display pipeline' error being thrown. I am very confused as I am not writing anything to the display pipeline. My worry is that I am modifying something that grasshopper later uses but for the life of me cannot see the problem.

Component

using System;
using System.Collections.Generic;

using Grasshopper.Kernel;
using Rhino.Geometry;

namespace Load_Take_Down_Tool.Components
{
    // This componenet takes care of creating ordered lists to pass to the column component
    // Searches for points within tributary areas
    public class Column_Organiser : GH_Component
    {
        /// <summary>
        /// Initializes a new instance of the Column_Organiser class.
        /// </summary>
        public Column_Organiser()
            : base("Column Organiser", "CO",
                "Orders lists of points and areas",
                "Load Take Down Tool", "Pre-Processing")
        {
        }

        /// <summary>
        /// Registers all the input parameters for this component.
        /// </summary>
        protected override void RegisterInputParams(GH_Component.GH_InputParamManager pManager)
        {
            pManager.AddPointParameter("Column", "C", "Unsorted points at location of column (required)", GH_ParamAccess.list);
            pManager.AddBrepParameter("Tributary Area", "T", "Unsorted tributary areas for column (required)", GH_ParamAccess.list);
        }

        /// <summary>
        /// Registers all the output parameters for this component.
        /// </summary>
        protected override void RegisterOutputParams(GH_Component.GH_OutputParamManager pManager)
        {
            pManager.AddPointParameter("Column", "C", "Sorted points at location of column", GH_ParamAccess.list);
            pManager.AddBrepParameter("Tributary Area", "T", "Sorted tributary areas for column", GH_ParamAccess.list);
            pManager.AddPointParameter("Failing Points", "FP", "Points that are not within any tributary area", GH_ParamAccess.list);
        }

        /// <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)
        {
            //Declare lists to hold data
            //uo = un-ordered
            //o = ordered
            List<Point3d> uocolumnpoints = new List<Point3d>();
            List<Brep> uotribareas = new List<Brep>();
            List<Point3d> failpoints = new List<Point3d>();

            //Get data from inputs
            if (!DA.GetDataList(0, uocolumnpoints))
                return;
            if (!DA.GetDataList(1, uotribareas))
                return;

            //Error if number of points and areas are not equal
            if (uocolumnpoints.Count != uotribareas.Count)
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Unequal number of columns and tributary areas");
                return;
            }

            List<Point3d> ocolumnpoints = new List<Point3d>();
            List<Curve> ocurves = new List<Curve>();
            List<Brep> otribareas = new List<Brep>();

            double m_tol = 0.001;

            string unitSystem = Rhino.RhinoDoc.ActiveDoc.GetUnitSystemName(true, true, true, true);

            if (unitSystem == "m")
                m_tol = 0.000001;
            if (unitSystem == "mm")
                m_tol = 0.011;

            PointsInsideCurves pic = new PointsInsideCurves();
            try
            {
                pic = new PointsInsideCurves(uocolumnpoints, uotribareas, m_tol);
            }
            catch (Exception ex)
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Remark, ex.Message);
            }
            failpoints = pic.FailedPoints;
            ocurves = pic.OrganisedCurves;

            if (failpoints.Count > 0)
                AddRuntimeMessage(GH_RuntimeMessageLevel.Remark, "Some point(s) did not lie within a tributary area, were on the boundary/tolerance limit of of a tributary area, or multiple points were within the same tributary area. See output FP for the points that have failed");

            foreach (Curve c in ocurves)
            {
                Brep b = Brep.TryConvertBrep(c);
                otribareas.Add(b);
            }
            
            //Pass data to outputs
            DA.SetDataList(0, ocolumnpoints);
            DA.SetDataList(1, otribareas);
            DA.SetDataList(2, failpoints);
        }

        //Grasshopper icon for component
        protected override System.Drawing.Bitmap Icon
        {
            get
            {
                return Properties.Resources.ColumnOrganiser;
            }
        }

        /// <summary>
        /// Gets the unique ID for this component. Do not change this ID after release.
        /// </summary>
        public override Guid ComponentGuid
        {
            get { return new Guid("{3259e465-5400-48e3-907b-fcb7455b12aa}"); }
        }
    }
}

Helper class

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Rhino.Geometry;

namespace Load_Take_Down_Tool
{
    class PointsInsideCurves
    {
        private List<Point3d> Points { get; set; }
        private List<Curve> ClosedCurves { get; set; }
        private double Tolerance { get; set; }
        public List<Point3d> FailedPoints { get; set; }
        public List<Curve> OrganisedCurves { get; set; }

        public PointsInsideCurves()
        {
        }

        public PointsInsideCurves(List<Point3d> Points, List<Curve> ClosedCurves, double Tolerance)
        {
            this.Points = Points;
            this.ClosedCurves = ClosedCurves;
            this.Tolerance = Tolerance;

            Evaluate();
        }

        public PointsInsideCurves(List<Point3d> Points, List<Brep> ClosedBreps, double Tolerance)
        {
            this.Points = Points;
            this.Tolerance = Tolerance;

            List<Curve> Curves = new List<Curve>();

            foreach (Brep b in ClosedBreps)
            {
                Curve[] c = b.DuplicateEdgeCurves();
                c = Curve.JoinCurves(c, Tolerance);
                Curves.Add(c[0]);
            }

            this.ClosedCurves = Curves;

            Evaluate();
        }

        private void Evaluate()
        {
            //Sorts in order of points
            //Naive implementation
            //Can update to KD tree if necessary            
            List<Curve> OrderedCurves = new List<Curve>();
            List<Point3d> fPoints = new List<Point3d>();

            //Have to duplicate the input list of curves to modify as we go
            List<Curve> CCDup = this.ClosedCurves;

            foreach (Point3d Point in this.Points)
            {
                //Backwards loop to allow removal
                bool assigned = false;

                for (int i = CCDup.Count - 1; i >= 0; i--)
                {
                    if (CCDup[i].IsClosed == false)
                    {
                        throw new Exception("Curve is not closed");
                    }

                    if (CCDup[i].Contains(Point) == PointContainment.Inside)
                    {
                        OrderedCurves.Add(CCDup[i]);
                        CCDup.RemoveAt(i);
                        assigned = true;
                        break;
                    }
                }

                //If point not within any of the given breps put null in the list
                if (assigned == false)
                {
                    OrderedCurves.Add(null);
                    fPoints.Add(Point);
                }
            }

            this.FailedPoints = fPoints;
            this.OrganisedCurves = OrderedCurves;
        }
    }
}

Views: 1489

Replies to This Discussion

Thought I would upload the files that I have pasted above to make anyone who might wish to help me life easier!

Attachments:

I think this is actually related to the other problem I was bumping into, please see this thread: http://www.grasshopper3d.com/forum/topics/document-collected-exception

RSS

About

Translate

Search

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service