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); }
/// <summary> /// Splits the curve at a specified track section value /// </summary> /// <param name="trackSectionValue"></param> /// <returns></returns> public TrackCurve[] Split(double trackSectionValue) { TrackCurve[] tcs = new TrackCurve[2]; double t; TrackSection splitTS; if (!FindSection(trackSectionValue, out splitTS)) { throw new Exception("Track curve split attempt failed. Track section value does not exist within track curve"); } Curve.ClosestPoint(splitTS.TrackSectionPlane.Origin, out t); Curve[] crvs = Curve.Split(t); tcs[0] = new TrackCurve(crvs[0]); tcs[1] = new TrackCurve(crvs[1]); foreach (TrackSection tc in TrackSections) { if (tc.StartVal <= trackSectionValue) // For a trackSectionValue that exists in a track section, add the track section to both parts { tcs[0].AddTrackSection(tc); } if (tc.StartVal >= trackSectionValue) { tcs[1].AddTrackSection(tc); } } return(tcs); }
protected override void SolveInstance(IGH_DataAccess DA) { string p = ""; Point3d sPt = Point3d.Unset; bool b = false; double tol = 1.0; if (!DA.GetData(0, ref p)) { return; } if (!DA.GetData(1, ref sPt)) { return; } if (!DA.GetData(2, ref b)) { return; } DA.GetData(3, ref tol); // Recalculate tolerance to be in correct (local) units tol *= RhinoUtilities.ScalingFactor(); if (b) { // Get raw data List <string[, ]> data = ExcelTools.ExcelUtilities.GetAllData2(p); if (data.Count != 2) { AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Excel file containing " + data.Count + " worksheet(s) rather than the expected 2. File correct?"); if (data.Count < 2) { return; } } // Get subsets string[,] xyProfileData = GetXYProfileData(data[0]); string[,] hProfileData = GetHeightProfileData(data[1]); //Create plane curve TrackCurve xyTC = CreateXYProfileTrackCurve(xyProfileData, tol); TrackCurve hTC = CreateHeightProfileCurve(hProfileData); TrackCurve combTC = TrackCurveUtilities.JoinTrackCurves(xyTC, hTC, tol); xyTC.Translate((Vector3d)sPt); hTC.Translate((Vector3d)sPt); combTC.Translate((Vector3d)sPt); DA.SetData(0, xyTC); DA.SetData(1, hTC); DA.SetData(2, combTC); //DA.SetData(3, CurveDebug); } }
protected override void SolveInstance(IGH_DataAccess DA) { TrackCurve tc = null; if (!DA.GetData(0, ref tc)) { return; } DA.SetData(0, tc.Curve); DA.SetDataList(1, tc.TrackSections); }
/// <summary> /// Joins a planar xy track curve and a planar height curve /// </summary> /// <param name="xyTrackCurve"></param> /// <param name="hTrackCurve"></param> /// <param name="tolerance"></param> /// <returns></returns> public static TrackCurve JoinTrackCurves(TrackCurve xyTrackCurve, TrackCurve hTrackCurve, double tolerance) { // Find common start and end point double startVal = FindHighestStartVal(xyTrackCurve, hTrackCurve); double endVal = FindLowestEndVal(xyTrackCurve, hTrackCurve); // Divide both curves so that they start and stop at same section xyTrackCurve = xyTrackCurve.RemoveStartSegment(startVal); xyTrackCurve = xyTrackCurve.RemoveEndSegment(endVal); hTrackCurve = hTrackCurve.RemoveStartSegment(startVal); hTrackCurve = hTrackCurve.RemoveEndSegment(endVal); // Divide into normalised parameters // Check so that tolerance is ok // Create new points int nSegments = (int)Math.Ceiling((xyTrackCurve.TrackSections[xyTrackCurve.TrackSections.Count - 1].EndVal - xyTrackCurve.TrackSections[0].StartVal) / tolerance); List <Point3d> hPts = SplitHTrackCurve(hTrackCurve.Curve, nSegments); Point3d[] oPts; xyTrackCurve.Curve.DivideByCount(nSegments, true, out oPts); List <Point3d> xyPts = oPts.ToList(); List <Point3d> combinedPts = new List <Point3d>(); for (int i = 0; i < hPts.Count; i++) { combinedPts.Add(new Point3d(xyPts[i].X, xyPts[i].Y, hPts[i].Z)); } // Interpolate curve Curve c = Curve.CreateInterpolatedCurve(combinedPts, 3); // Add all track sections TrackCurve oTC = new TrackCurve(c); foreach (TrackSection ts in xyTrackCurve.TrackSections) { UpdateXYTrackSection(ts, c, tolerance); oTC.AddTrackSection(ts); } foreach (TrackSection ts in hTrackCurve.TrackSections) { UpdateHTrackSection(ts, hTrackCurve.Curve, c, tolerance); oTC.AddTrackSection(ts); } // Update section directions oTC.UpdateSectionDirection(); return(oTC); }
private static double FindLowestEndVal(TrackCurve tc1, TrackCurve tc2) { double endVal = -1; if (tc1.TrackSections[tc1.TrackSections.Count - 1].EndVal > tc2.TrackSections[tc2.TrackSections.Count - 1].EndVal) { endVal = tc2.TrackSections[tc2.TrackSections.Count - 1].EndVal; } else { endVal = tc1.TrackSections[tc1.TrackSections.Count - 1].EndVal; } return(endVal); }
private static double FindHighestStartVal(TrackCurve tc1, TrackCurve tc2) { double startVal = -1; if (tc1.TrackSections[0].StartVal < tc2.TrackSections[0].StartVal) { startVal = tc2.TrackSections[0].StartVal; } else { startVal = tc1.TrackSections[0].StartVal; } return(startVal); }
/////////////////////////////// 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); } }
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); } }