Beispiel #1
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            string s = "";

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

            TrackCurve tc = null;

            if (!DA.GetData(1, ref tc))
            {
                return;
            }

            TrackSection ts = null;

            try
            {
                if (!tc.FindSection(s, out ts))
                {
                    AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Section value exceeds the boundaries of the track curve");
                }
            }
            catch (Exception e)
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Error, e.Message);
            }

            DA.SetData(0, ts);
        }
Beispiel #2
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            TrackSection ts = new TrackSection(Plane.WorldYZ, 0);

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

            DA.SetData(0, ts.TrackSectionPlane);
            DA.SetData(1, ts.GetTrackSectionString());
            DA.SetData(2, ts.StartVal);
        }
Beispiel #3
0
 private TrackSection CreateTrackSectionConnection(string trackSectionConnection, Point3d sPt, Curve currCrv)
 {
     try
     {
         return(new TrackSectionConnection(TrackSection.FindTrackPlaneOnCurve(currCrv, sPt), trackSectionConnection));
     }
     catch (Exception)
     {
         AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Unexpected exception found while creating track section " + trackSectionConnection +
                           " at " + sPt.ToString());
         throw;
     }
 }
Beispiel #4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="val">Track section value</param>
        /// <param name="ts">Output section</param>
        /// <returns>True if submitted value is in range, false otherwise</returns>
        public bool FindSection(double val, out TrackSection ts)
        {
            ts = null;

            // Check whether value is within range
            if (val < TrackSections[0].StartVal || val > TrackSections[TrackSections.Count - 1].EndVal)
            {
                return(false);
            }

            // Find first section before point
            TrackSection tsBefore = null;

            for (int i = 0; i < TrackSections.Count - 1; i++)
            {
                if (TrackSections[i].StartVal <= val && TrackSections[i + 1].EndVal >= val)
                {
                    tsBefore = TrackSections[i];
                }
            }

            if (tsBefore == null)
            {
                throw new Exception("Track section not found");
            }


            // Find distance between sections
            double distance = val - tsBefore.StartVal;

            double t1, t2;

            Curve.ClosestPoint(tsBefore.TrackSectionPlane.Origin, out t1);
            Curve c2;

            if (Curve.Domain.T0 == t1 || Curve.Domain.T1 == t1)    // If attempting to split at start or end point, use entire curve
            {
                c2 = Curve;
            }
            else
            {
                c2 = Curve.Split(t1)[1];
            }

            c2.LengthParameter(distance, out t2);

            // Return the track section on the first curve
            ts = TrackSection.FindTrackSectionOnCurve(Curve, c2.PointAt(t2), val);

            return(true);
        }
Beispiel #5
0
        /// <summary>
        /// Updates the height curve sections to a new 3d curve
        /// </summary>
        /// <param name="ts"></param>
        /// <param name="c1">The original height curve</param>
        /// <param name="c2">The new 3d curve</param>
        private static void UpdateHTrackSection(TrackSection ts, Curve c1, Curve c2, double tolerance)
        {
            double t1;

            c1.ClosestPoint(ts.TrackSectionPlane.Origin, out t1);
            Interval iv     = new Interval(c1.Domain.T0, t1);
            double   length = c1.GetLength(iv);

            // Make projection of xy curve for length to be correct
            Curve c3 = c2.DuplicateCurve();

            c3.Transform(Rhino.Geometry.Transform.PlanarProjection(Plane.WorldXY));

            ts.Translate(c3.PointAtLength(length) - ts.TrackSectionPlane.Origin);
            UpdateXYTrackSection(ts, c2, tolerance);
        }
Beispiel #6
0
        public void UpdateSectionDirection()
        {
            for (int i = 0; i < TrackSections.Count; i++)
            {
                TrackSection ts = TrackSections[i];

                double t;
                Curve.ClosestPoint(ts.TrackSectionPlane.Origin, out t);

                Vector3d tangent = Curve.TangentAt(t);
                double   angle   = Vector3d.VectorAngle(ts.TrackSectionPlane.Normal, tangent, Plane.WorldXY);

                ts.RotatePlane(angle, Vector3d.ZAxis);

                TrackSections[i] = ts;
            }
        }
Beispiel #7
0
        /// <summary>
        /// Updates an xy track section to a new 3d curve. For the method to work as intended the xy curve should lie directly above the origin of the track section plane
        /// </summary>
        /// <param name="ts"></param>
        /// <param name="c"></param>
        /// <returns></returns>
        private static void UpdateXYTrackSection(TrackSection ts, Curve c, double tolerance)
        {
            var events = Rhino.Geometry.Intersect.Intersection.CurvePlane(c, ts.TrackSectionPlane, tolerance);

            if (events != null)
            {
                if (events.Count != 1)
                {
                    throw new Exception(
                              "Curve/plane intersection failed. Only one intersection point expected, number of intersection points found: " + events.Count);
                }
                else
                {
                    if (events[0].IsPoint)
                    {
                        ts.Translate(events[0].PointA - ts.TrackSectionPlane.Origin);
                    }
                    else if (events[0].IsOverlap)
                    {
                        ts.Translate(((events[0].PointA + events[0].PointB) / 2) - ts.TrackSectionPlane.Origin);
                    }
                }
            }
        }
Beispiel #8
0
 /// <summary>
 /// Adds the section in the correct place, i.e. sorts the sections from lowest to highest
 /// </summary>
 /// <param name="ts"></param>
 public void AddTrackSection(TrackSection ts)
 {
     TrackSections.Add(ts);
     TrackSections = TrackSections.OrderBy(t => t.StartVal).ToList();
 }
Beispiel #9
0
        public bool FindSection(string s, out TrackSection ts)
        {
            ts = null;

            return(FindSection(TrackSection.GetValueFromSectionString(s), out ts));
        }
Beispiel #10
0
        private bool CreateTrackSectionConnection(string trackSectionConnection, Point3d sPt, Curve currCrv, out TrackSection tsc)
        {
            double t;

            if (currCrv.ClosestPoint(sPt, out t, 1 / RhinoUtilities.ScalingFactor()))
            {
                tsc = CreateTrackSectionConnection(trackSectionConnection, sPt, currCrv);
                return(true);
            }
            else
            {
                tsc = null;
                return(false);
            }
        }
Beispiel #11
0
        /////////////////////////////// HEIGHT ///////////////////////////////

        private TrackCurve CreateHeightProfileCurve(string[,] hProfileData)
        {
            List <Curve>        crvs = new List <Curve>();
            List <TrackSection> ts   = new List <TrackSection>();

            Point3d sPt  = CreateFirstHeightPoint(hProfileData);
            Point3d cePt = new Point3d(sPt.X, sPt.Y, sPt.Z);
            bool    b;

            for (int i = 0; i < hProfileData.GetLength(0); i++)
            {
                b = false;
                if (hProfileData[i, 0] == "Raklinje")
                {
                    crvs.Add(CreateHeightLine(hProfileData, i, cePt, 1).ToNurbsCurve());       // DEBUG TOLERANCE!
                    b = true;
                }

                else if (hProfileData[i, 0] == "Cirkulär")
                {
                    crvs.Add(CreateHeightArc(hProfileData, i, cePt, 1).ToNurbsCurve());       // DEBUG TOLERANCE!
                    b = true;
                }

                // Update current end point if curve has been added
                if (b)
                {
                    cePt = crvs[crvs.Count - 1].PointAtEnd;
                }


                // Create track section
                if (hProfileData[i, 1].StartsWith("KM"))
                {
                    TrackSection tc = null;

                    if (b || hProfileData[i, 0] == "Slutsektion")
                    {
                        if (CreateTrackSection(hProfileData[i, 1], crvs[crvs.Count - 1].PointAtStart, crvs[crvs.Count - 1], out tc))
                        {
                            ts.Add(tc);
                        }
                    }

                    else
                    {
                        if (CreateTrackSectionConnection(hProfileData[i, 1], cePt, crvs[crvs.Count - 1], out tc))
                        {
                            ts.Add(tc);
                        }
                    }
                }
            }

            Curve[] oCrvs = Curve.JoinCurves(crvs);
            if (oCrvs.Length != 1)
            {
                string message = "Error: more than one height curve created.";
                AddRuntimeMessage(GH_RuntimeMessageLevel.Error, message);
                throw new Exception(message);
            }
            else
            {
                TrackCurve tc = new TrackCurve(oCrvs[0], ts);

                // Move to origo
                Vector3d v = new Vector3d(-crvs[0].PointAtStart.X, 0, 0);
                tc.Translate(v);

                return(tc);
            }
        }
Beispiel #12
0
        private TrackCurve CreateXYProfileTrackCurve(string[,] xyProfileData, double tol)
        {
            List <Curve>        crvs = new List <Curve>();
            List <TrackSection> tcs  = new List <TrackSection>();

            for (int i = 0; i < xyProfileData.GetLength(0); i++)
            {
                if (xyProfileData[i, 1] == "RL")
                {
                    crvs.Add(CreateXYLine(xyProfileData, i).ToNurbsCurve());
                }

                else if (xyProfileData[i, 1] == "C")
                {
                    crvs.Add(CreateXYArc(xyProfileData, i).ToNurbsCurve());
                }

                else if (xyProfileData[i, 1] == "ÖK")
                {
                    crvs.Add(CreateXYClothoid(xyProfileData, i, tol).ToNurbsCurve());
                }

                // Create track sections
                if (xyProfileData[i, 2].StartsWith("KM"))
                {
                    TrackSection tc = null;

                    if (xyProfileData[i, 1] != "")
                    {
                        if (CreateTrackSection(xyProfileData[i, 2], crvs[crvs.Count - 1].PointAtStart, crvs[crvs.Count - 1], out tc))
                        {
                            tcs.Add(tc);
                        }

                        else // Maybe add another check here
                        if (CreateTrackSectionConnection(xyProfileData[i, 2], crvs[crvs.Count - 1].PointAtEnd, crvs[crvs.Count - 1], out tc))
                        {
                            tcs.Add(tc);
                        }
                    }
                }
            }


            Curve[] jCrvs = Curve.JoinCurves(crvs);
            //CurveDebug = jCrvs[0];                      //DEBUG
            if (jCrvs.Length > 1)
            {
                throw new Exception("Unable to join curves");
            }
            else
            {
                // Join and add track sections
                TrackCurve tc = new TrackCurve(jCrvs[0]);
                tc.AddTrackSection(tcs);

                // Vector from start point of curve to origin
                Vector3d v = new Vector3d(jCrvs[0].PointAtStart);
                v.Reverse();
                tc.Translate(v);

                return(tc);
            }
        }