/// <summary> /// This function creates curves between points /// </summary> /// <param name="pointer"></param> /// <param name="doc"></param> /// <param name="through"></param> public static void XCurveFromPoints(Point3dList pointer, RhinoDoc doc, bool through) { if (through) { //create a curve through points Curve curve = Curve.CreateInterpolatedCurve(pointer, 3); if (curve != null && curve.IsValid) { doc.Objects.AddCurve(curve); doc.Views.Redraw(); } } else { //use points as control points NurbsCurve curve = NurbsCurve.Create(false, 3, pointer); if (curve != null && curve.IsValid) { doc.Objects.AddCurve(curve); doc.Views.Redraw(); } } }
public GsaMember1d Duplicate() { GsaMember1d dup = new GsaMember1d { m_member = m_member //add clone or duplicate if available }; if (m_crv != null) { dup.m_crv = m_crv.DuplicatePolyCurve(); } Point3dList point3Ds = new Point3dList(m_topo); dup.Topology = new List <Point3d>(point3Ds.Duplicate()); dup.TopologyType = m_topoType.ToList(); dup.ID = m_id; if (m_rel1 != null) { dup.ReleaseStart = m_rel1.Duplicate(); } if (m_rel2 != null) { dup.ReleaseEnd = m_rel2.Duplicate(); } if (m_section != null) { dup.Section = m_section.Duplicate(); } return(dup); }
/// <summary> /// This function selects points /// </summary> /// <param name="message"></param> /// <param name="pointer"></param> public static void XSelectPoints(string message, out Point3dList pointer) { // variables are: // string message // out Point3dList points - the out won't be recognized unless you have Rhino.Collections and the 'out parameters // have to be filled in the function. // don't need a doc because we won't write anything to the document table, only reading. pointer = new Point3dList(); var go = new GetObject(); go.GeometryFilter = Rhino.DocObjects.ObjectType.Point; go.SetCommandPrompt(message); go.GetMultiple(1, 0); if (go.CommandResult() != Result.Success) { return; } for (var i = 0; i < go.ObjectCount; i++) { var point = go.Object(i).Point(); if (null != point) { pointer.Add(point.Location); } } }
public static void TestPolygonSelect() { Document doc = Application.DocumentManager.MdiActiveDocument; Editor ed = doc.Editor; //声明一个Point3d类列表对象,用于存储多段线的顶点 Point3dList pts = new Point3dList(); //提示用户选择多段线 PromptEntityResult per = ed.GetEntity("请选择多段线"); if (per.Status != PromptStatus.OK) { return; //选择错误,返回 } using (Transaction trans = doc.TransactionManager.StartTransaction()) { //转换为Polyline对象 Polyline pline = trans.GetObject(per.ObjectId, OpenMode.ForRead) as Polyline; if (pline != null) { //遍历所选多段线的顶点并添加到Point3d类列表 for (int i = 0; i < pline.NumberOfVertices; i++) { Point3d point = pline.GetPoint3dAt(i); pts.Add(point); } //窗口选择,仅选择完全位于多边形区域中的对象 PromptSelectionResult psr = ed.SelectWindowPolygon(pts); if (psr.Status == PromptStatus.OK) { Application.ShowAlertDialog("选择集中实体的数量:" + psr.Value.Count.ToString()); } } trans.Commit(); } }
/// <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) { // 1. Declare placeholder variables var struts = new List<Curve>(); double tol = 0.0; // 2. Attempt to retrieve input if (!DA.GetDataList(0, struts)) { return; } if (!DA.GetData(1, ref tol)) { return; } // 3. Validate input if (struts == null || struts.Count == 1) { return; } if (tol < 0) { return; } // 4. Call cleaning method var nodes = new Point3dList(); var nodePairs = new List<IndexPair>(); struts = FrameTools.CleanNetwork(struts, tol, out nodes, out nodePairs); // 5. Organize index lists var strutStart = new List<int>(); var strutEnd = new List<int>(); foreach (IndexPair nodePair in nodePairs) { strutStart.Add(nodePair.I); strutEnd.Add(nodePair.J); } // 6. Set output DA.SetDataList(0, struts); DA.SetDataList(1, nodes); DA.SetDataList(2, strutStart); DA.SetDataList(3, strutEnd); }
public froGHRTree(Mesh mesh) { Point3d[] vertices = mesh.Vertices.ToPoint3dArray(); Points = new Point3dList(vertices); Source = EnumRTreeType.Mesh; Tree = RTree.CreateFromPointArray(vertices); }
/// <summary> /// Removes duplicate/invalid/tiny curves and outputs the cleaned list, and a list of unique nodes. /// </summary> public static List <Curve> CleanNetwork(List <Curve> inputStruts, double tol, out Point3dList nodes) { nodes = new Point3dList(); var nodePairs = new List <IndexPair>(); return(CleanNetwork(inputStruts, tol, out nodes, out nodePairs)); }
public GsaElement2d Duplicate() { GsaElement2d dup = new GsaElement2d { m_elements = m_elements //add clone or duplicate if available }; if (m_mesh != null) { dup.m_mesh = (Mesh)m_mesh.Duplicate(); Point3dList point3Ds = new Point3dList(m_topo); dup.Topology = new List <Point3d>(point3Ds.Duplicate()); dup.m_topoInt = m_topoInt.ToList(); } if (m_id != null) { int[] dupids = new int[m_id.Count]; m_id.CopyTo(dupids); dup.ID = new List <int>(dupids); } if (m_props != null) { GsaProp2d[] dupprop = new GsaProp2d[m_props.Count]; m_props.CopyTo(dupprop); dup.Properties = new List <GsaProp2d>(dupprop); } return(dup); }
public override IGH_GeometricGoo Transform(Transform xform) { if (Value == null) { return(null); } if (Value.PolyCurve == null) { return(null); } GsaMember1d mem = Value.Duplicate(); List <Point3d> pts = Value.Topology.ToList(); Point3dList xpts = new Point3dList(pts); xpts.Transform(xform); mem.Topology = xpts.ToList(); mem.TopologyType = Value.TopologyType.ToList(); if (Value.PolyCurve != null) { PolyCurve crv = Value.PolyCurve.DuplicatePolyCurve(); crv.Transform(xform); mem.PolyCurve = crv; } return(new GsaMember1dGoo(mem)); }
/// <summary> /// Removes duplicate/invalid/tiny curves and outputs the cleaned list, and a list of unique nodes. /// </summary> public static List<Curve> CleanNetwork(List<Curve> inputStruts, double tol, out Point3dList nodes) { nodes = new Point3dList(); var nodePairs = new List<IndexPair>(); return CleanNetwork(inputStruts, tol, out nodes, out nodePairs); }
/// <summary> /// Instance constructor based on a list of lines. /// </summary> public UnitCell(List<Line> rawCell) { m_nodes = new Point3dList(); m_nodePairs = new List<IndexPair>(); m_nodePaths = new List<int[]>(); ExtractTopology(rawCell); NormaliseTopology(); }
public ErosionSim(Mesh M, List <Point3d> pts, double maxSpeed) { this.M = M; Morig = new Mesh(); Morig.CopyFrom(M); this.maxSpeed = maxSpeed; p1 = new Point3dList(M.Vertices.ToPoint3dArray()); initParts(pts); }
public void SetCornerPts(Point3dList newcornerpts) { if (cornerpts != null) { cornerpts.Clear(); } cornerpts = newcornerpts; }
/// <summary> /// Instance constructor based on a list of lines. /// </summary> public UnitCell(List <Line> rawCell) { m_nodes = new Point3dList(); m_nodePairs = new List <IndexPair>(); m_nodePaths = new List <int[]>(); ExtractTopology(rawCell); NormaliseTopology(); }
public froGHRTree(List <Point3d> points) { Points = new Point3dList(); Source = EnumRTreeType.Points; Tree = new RTree(); for (int i = 0; i < points.Count; i++) { Points.Add(points[i]); Tree.Insert(points[i], i); } }
// constructor public ErosionSim(Mesh M, List <Point3d> P) { this.M = M; Morig = new Mesh(); Morig.CopyFrom(M); vertexList = new Point3dList(M.Vertices.ToPoint3dArray()); parts = new List <Particle>(); foreach (Point3d p in P) { parts.Add(new Particle(this, p)); } }
//weighted random populate point with attractors //reference Junichiro Horikawa on Github Point3dList Populate(Brep brep, double n, int ite, List <Point3d> attractors, double attractor_r, double attractor_strength) { var points = new Point3dList(); int num = Convert.ToInt32(n); if (brep != null) { var attracts = new Point3dList(attractors); var rnd = new Random(); var bbox = brep.GetBoundingBox(true); attractor_strength = (-1) * attractor_strength; for (int i = 0; i < num; i++) { if (points.Count == 0) { var rndpt = CreateRandomPoint(rnd, brep, bbox); points.Add(rndpt); } else { double fdist = -1; Point3d fpt = new Point3d(); for (int t = 0; t < Math.Max(Math.Min(ite, i), 10); t++) { var nrndpt = CreateRandomPoint(rnd, brep, bbox); var nindex = points.ClosestIndex(nrndpt); var npts = points[nindex]; var ndist = npts.DistanceTo(nrndpt); if (attractor_strength != 0) { var nattractid = attracts.ClosestIndex(nrndpt); var nattarctpts = attracts[nattractid]; var mindist = attractor_r; var pow = attractor_strength; var nattractdist = Math.Pow(Remap(Math.Min(nattarctpts.DistanceTo(nrndpt), mindist), 0, mindist, 0, 1.0), pow); ndist *= nattractdist; } if (fdist < ndist) { fdist = ndist; fpt = nrndpt; } } points.Add(fpt); } } } return(points); }
/// <summary> /// This function creates polyline from points /// </summary> /// <param name="pointer"></param> /// <param name="doc"></param> /// /// public static void XPolylineFromPoints(Point3dList pointer, RhinoDoc doc) { Polyline pline = new Polyline(pointer); pline.Add(pline[0]); //this will close the polyline if (pline != null && pline.IsValid) { doc.Objects.AddPolyline(pline); } doc.Views.Redraw(); }
/// <summary> /// This function creates lines from points /// </summary> /// <param name="pointer"></param> /// <param name="doc"></param> /// /// public static void XLinesFromPoints(Point3dList pointer, RhinoDoc doc) { for (var i = 0; i < pointer.Count - 1; i++) { Line line = new Line(pointer[i], pointer[i + 1]); if (line != null && line.IsValid) { doc.Objects.AddLine(line); } } doc.Views.Redraw(); }
protected Polyline generateFingerJoint(Line jointLine, double thickness) { Point3d currPoint = new Point3d(jointLine.FromX, jointLine.FromY, 0); Point3dList points = new Point3dList(); points.Add(currPoint); double xIncr, yIncr; yIncr = thickness; xIncr = thickness / 2; // An even finger count means the finger will be drawn right of the // center line int fingerCount = 0; int fingerDirection = -1; // Loop invariant: incrementing and placing current point will always // result in a point before the stoppingY while (currPoint.Y + yIncr <= jointLine.ToY) { // Multiplier for right finger on even, vice versa for odd fingerDirection = fingerCount % 2 == 0 ? 1 : -1; currPoint += new Vector3d(xIncr * fingerDirection, 0, 0); points.Add(currPoint); currPoint += new Vector3d(0, yIncr, 0); points.Add(currPoint); currPoint += new Vector3d(-xIncr * fingerDirection, 0, 0); points.Add(currPoint); fingerCount += 1; } // Finish the last truncated finger if necessary if (currPoint.Y < jointLine.ToY) { fingerDirection = fingerCount % 2 == 0 ? 1 : -1; currPoint += new Vector3d(xIncr * fingerDirection, 0, 0); points.Add(currPoint); currPoint += new Vector3d(0, jointLine.ToY - currPoint.Y, 0); points.Add(currPoint); currPoint += new Vector3d(-xIncr * fingerDirection, 0, 0); points.Add(currPoint); } return(new Polyline(points)); }
/// <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) { // 1. Declare placeholder variables var struts = new List <Curve>(); double tol = 0.0; // 2. Attempt to retrieve input if (!DA.GetDataList(0, struts)) { return; } if (!DA.GetData(1, ref tol)) { return; } // 3. Validate input if (struts == null || struts.Count == 1) { return; } if (tol < 0) { return; } // 4. Call cleaning method var nodes = new Point3dList(); var nodePairs = new List <IndexPair>(); struts = FrameTools.CleanNetwork(struts, tol, out nodes, out nodePairs); // 5. Organize index lists var strutStart = new List <int>(); var strutEnd = new List <int>(); foreach (IndexPair nodePair in nodePairs) { strutStart.Add(nodePair.I); strutEnd.Add(nodePair.J); } // 6. Set output DA.SetDataList(0, struts); DA.SetDataList(1, nodes); DA.SetDataList(2, strutStart); DA.SetDataList(3, strutEnd); }
/// <summary> /// Gets all Greville (Edit) points for this curve. /// </summary> public Point3dList GrevillePoints() { double[] gr_ab = GrevilleParameters(); if (gr_ab == null) { return(null); } Point3dList gr_pts = new Point3dList(gr_ab.Length); foreach (double t in gr_ab) { gr_pts.Add(PointAt(t)); } return(gr_pts); }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { Random r = new Random(13); var plcnt = 1000000; var edge = 10; GetNumber gn = new GetNumber(); gn.SetCommandPrompt("How many pointsies"); gn.SetDefaultInteger(plcnt); gn.SetUpperLimit(500000001, true); gn.SetLowerLimit(1, true); gn.AcceptNothing(true); var gnrc = gn.Get(); if (gnrc == GetResult.Nothing || gnrc == GetResult.Number) { var nr = (int)gn.Number(); if (nr > 500000000) { RhinoApp.WriteLine("More than 500.000.000 points"); return(Result.Cancel); } pc = new PointCloud(); Point3dList p3dlist = new Point3dList(nr); List <System.Drawing.Color> collist = new List <System.Drawing.Color>(nr); for (int i = 0; i < nr; i++) { var d = (double)i; p3dlist.Add(new Point3d(r.NextDouble() * edge, r.NextDouble() * edge, r.NextDouble() * edge)); collist.Add(System.Drawing.Color.FromArgb(r.Next(0, 255), r.Next(0, 255), r.Next(0, 255))); } pc.AddRange(p3dlist, collist); cnd.ThePc = pc; cnd.Enabled = true; } doc.Views.Redraw(); return(Result.Success); }
public GsaNode Duplicate() { GsaNode dup = new GsaNode { Node = Node //add clone or duplicate if available }; Point3dList pt = new Point3dList(Point); Point3dList duppt = pt.Duplicate(); dup.Point = duppt[0]; if (m_id != 0) { dup.ID = m_id; } if (m_spring != null) { dup.Spring = m_spring.Duplicate(); } dup.m_plane = LocalAxis.Clone(); return(dup); }
/// <summary> /// Instace constructor based on a list of curves (i.e. a lattice). /// </summary> public ExoMesh(List <Curve> struts) { m_hulls = new List <ExoHull>(); m_sleeves = new List <ExoSleeve>(); m_plates = new List <ExoPlate>(); m_mesh = new Mesh(); double tol = RhinoDoc.ActiveDoc.ModelAbsoluteTolerance; // First, we convert the struts to a list of unique nodes and node pairs // We use the following lists to extract valid data from the input list var nodeList = new Point3dList(); // List of unique nodes var nodePairList = new List <IndexPair>(); // List of struts, as node index pairs struts = FrameTools.CleanNetwork(struts, tol, out nodeList, out nodePairList); // Set hull locations foreach (Point3d node in nodeList) { m_hulls.Add(new ExoHull(node)); } // Create sleeves, plates and relational indices for (int i = 0; i < struts.Count; i++) { m_sleeves.Add(new ExoSleeve(struts[i], nodePairList[i])); // Construct plates m_plates.Add(new ExoPlate(nodePairList[i].I, struts[i].TangentAtStart)); m_plates.Add(new ExoPlate(nodePairList[i].J, -struts[i].TangentAtEnd)); // Set sleeve relational parameters IndexPair platePair = new IndexPair(m_plates.Count - 2, m_plates.Count - 1); m_sleeves[i].PlatePair = platePair; // Set hull relational parameters m_hulls[nodePairList[i].I].SleeveIndices.Add(i); m_hulls[nodePairList[i].J].SleeveIndices.Add(i); m_hulls[nodePairList[i].I].PlateIndices.Add(platePair.I); m_hulls[nodePairList[i].J].PlateIndices.Add(platePair.J); } }
/// <summary> /// Instace constructor based on a list of curves (i.e. a lattice). /// </summary> public ExoMesh(List<Curve> struts) { m_hulls = new List<ExoHull>(); m_sleeves = new List<ExoSleeve>(); m_plates = new List<ExoPlate>(); m_mesh = new Mesh(); double tol = RhinoDoc.ActiveDoc.ModelAbsoluteTolerance; // First, we convert the struts to a list of unique nodes and node pairs // We use the following lists to extract valid data from the input list var nodeList = new Point3dList(); // List of unique nodes var nodePairList = new List<IndexPair>(); // List of struts, as node index pairs struts = FrameTools.CleanNetwork(struts, tol, out nodeList, out nodePairList); // Set hull locations foreach (Point3d node in nodeList) { m_hulls.Add(new ExoHull(node)); } // Create sleeves, plates and relational indices for (int i = 0; i < struts.Count; i++) { m_sleeves.Add(new ExoSleeve(struts[i], nodePairList[i])); // Construct plates m_plates.Add(new ExoPlate(nodePairList[i].I, struts[i].TangentAtStart)); m_plates.Add(new ExoPlate(nodePairList[i].J, -struts[i].TangentAtEnd)); // Set sleeve relational parameters IndexPair platePair = new IndexPair(m_plates.Count - 2, m_plates.Count - 1); m_sleeves[i].PlatePair = platePair; // Set hull relational parameters m_hulls[nodePairList[i].I].SleeveIndices.Add(i); m_hulls[nodePairList[i].J].SleeveIndices.Add(i); m_hulls[nodePairList[i].I].PlateIndices.Add(platePair.I); m_hulls[nodePairList[i].J].PlateIndices.Add(platePair.J); } }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { ObjRef obj_ref; const string prompt = "Select curve"; const ObjectType object_type = ObjectType.Curve; Result res = RhinoGet.GetOneObject(prompt, false, object_type, out obj_ref); if (res != Result.Success) { return(res); } Curve crv = obj_ref.Curve(); if (null == crv) { return(Result.Failure); } NurbsCurve nc = crv.ToNurbsCurve(); if (null == nc) { return(Result.Failure); } Point3dList points = nc.GrevillePoints(); foreach (Point3d point in points) { doc.Objects.AddPoint(point); } doc.Views.Redraw(); return(Result.Success); }
public override IGH_GeometricGoo Transform(Transform xform) { if (Value == null) { return(null); } if (Value.NgonMesh == null) { return(null); } GsaElement3d elem = Value.Duplicate(); Mesh xMs = elem.NgonMesh; xMs.Transform(xform); elem.NgonMesh = xMs; Point3dList pts = new Point3dList(Value.Topology); pts.Transform(xform); elem.Topology = pts.ToList(); return(new GsaElement3dGoo(elem)); }
/// <summary> /// This procedure contains the user code. Input parameters are provided as regular arguments, /// Output parameters as ref arguments. You don't have to assign output parameters, /// they will have a default value. /// </summary> private void RunScript(Point3d P0, int n, double evap, bool wrap, bool reset, bool go, bool MT, ref object P, ref object cPind, ref object nIndexes, ref object S) { // reset/initialize if (reset || diff == null || diff.ptsArray.Length != n * n) { diff = new Diffusion(n, n, wrap); ptsList = new Point3dList(diff.ptsArray); // create a Point3dList for faster closest point calculation cP = ptsList.ClosestIndex(P0); // find index of closest point to attractor diff.stigVal[cP] = 1; c = 0; // reset counter } if (go) { diff.evap = evap; cP = ptsList.ClosestIndex(P0); // find index of closest point to attractor if (MT) { diff.UpdateMT(); } else { diff.Update(); } diff.stigVal[cP] = 1; c++; Component.ExpireSolution(true); } P = diff.ptsArray.Select(x => new GH_Point(x)); S = diff.stigVal.Select(x => new GH_Number(x)); cPind = cP; // nIndexes = diff.GetNeighIndexes(); }
public GsaMember2d Duplicate() { GsaMember2d dup = new GsaMember2d { m_member = m_member //add clone or duplicate if available }; if (m_brep != null) { dup.m_brep = m_brep.DuplicateBrep(); } if (m_crv != null) { dup.m_crv = m_crv.DuplicatePolyCurve(); } Point3dList point3Ds = new Point3dList(m_topo); dup.Topology = new List <Point3d>(point3Ds.Duplicate()); dup.TopologyType = m_topoType.ToList(); if (void_crvs != null) { dup.void_crvs = new List <PolyCurve>(); dup.void_topo = new List <List <Point3d> >(); dup.void_topoType = new List <List <string> >(); for (int i = 0; i < void_crvs.Count; i++) { dup.void_crvs.Add(void_crvs[i].DuplicatePolyCurve()); Point3dList voidpoint3Ds = new Point3dList(void_topo[i]); dup.void_topo.Add(new List <Point3d>(voidpoint3Ds.Duplicate())); dup.void_topoType.Add(void_topoType[i].ToList()); } } if (incl_Lines != null) { dup.incl_Lines = new List <PolyCurve>(); dup.incLines_topo = new List <List <Point3d> >(); dup.inclLines_topoType = new List <List <string> >(); for (int i = 0; i < incl_Lines.Count; i++) { dup.incl_Lines.Add(incl_Lines[i].DuplicatePolyCurve()); Point3dList inclLinepoint3Ds = new Point3dList(incLines_topo[i]); dup.incLines_topo.Add(new List <Point3d>(inclLinepoint3Ds.Duplicate())); dup.inclLines_topoType.Add(inclLines_topoType[i].ToList()); } } if (m_prop != null) { dup.Property = m_prop.Duplicate(); } Point3dList inclpoint3Ds = new Point3dList(incl_pts); dup.incl_pts = new List <Point3d>(inclpoint3Ds.Duplicate()); dup.ID = m_id; if (m_prop != null) { dup.Property = m_prop.Duplicate(); } return(dup); }
public override IGH_GeometricGoo Transform(Transform xform) { if (Value == null) { return(null); } if (Value.Brep == null & Value.PolyCurve == null) { return(null); } GsaMember2d mem = new GsaMember2d { Member = Value.Member }; List <Point3d> pts = Value.Topology; Point3dList xpts = new Point3dList(pts); xpts.Transform(xform); mem.Topology = xpts.ToList(); mem.TopologyType = Value.TopologyType; if (Value.VoidTopology != null) { for (int i = 0; i < Value.VoidTopology.Count; i++) { xpts = new Point3dList(Value.VoidTopology[i]); xpts.Transform(xform); mem.VoidTopology.Add(xpts.ToList()); } mem.VoidTopologyType = Value.VoidTopologyType; } if (Value.InclusionLines != null) { for (int i = 0; i < Value.InclusionLines.Count; i++) { PolyCurve xLn = Value.InclusionLines[i]; xLn.Transform(xform); mem.InclusionLines.Add(xLn); } for (int i = 0; i < Value.IncLinesTopology.Count; i++) { xpts = new Point3dList(Value.IncLinesTopology[i]); xpts.Transform(xform); mem.IncLinesTopology.Add(xpts.ToList()); } mem.IncLinesTopologyType = Value.IncLinesTopologyType; } if (Value.InclusionPoints != null) { xpts = new Point3dList(Value.InclusionPoints); xpts.Transform(xform); mem.InclusionPoints = xpts.ToList(); } if (Value.Brep != null) { Brep brep = Value.Brep.DuplicateBrep(); brep.Transform(xform); mem.Brep = brep; } if (Value.PolyCurve != null) { PolyCurve crv = Value.PolyCurve.DuplicatePolyCurve(); crv.Transform(xform); mem.PolyCurve = crv; } return(new GsaMember2dGoo(mem)); }
/// <summary> /// Solves the instance. /// </summary> /// <param name="DA">Da.</param> protected override void SolveInstance(IGH_DataAccess DA) { // Properties Mesh mesh = null; Curve initialCurve = null; double specifiedDistance = 0.0; int maxCount = 0; double threshold = 0.0; double perpStepSize = 0.0; bool bothDir = false; double minThreshold = 0.0; // Set the input data if (!DA.GetData(0, ref mesh)) { return; } if (!DA.GetData(1, ref initialCurve)) { return; } if (!DA.GetData(2, ref bothDir)) { return; } if (!DA.GetData(3, ref maxCount)) { return; } if (!DA.GetData(4, ref threshold)) { return; } if (!DA.GetData(5, ref specifiedDistance)) { return; } if (!DA.GetData(6, ref perpStepSize)) { return; } if (!DA.GetData(7, ref minThreshold)) { return; } // Data validation if (maxCount == 0) { AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Count cannot be 0"); } if (!mesh.IsValid) { AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Mesh is invalid"); } // Placeholder properties DataTree <Curve> pattern = new DataTree <Curve>(); Curve previousCurve = initialCurve; List <Curve> perpGeods = new List <Curve>(); List <double> perpParams = new List <double>(); // Start piecewise evolution process for (int i = 0; i < maxCount; i++) { Debug.WriteLine("Iter " + i); // Create placeholder lists perpGeods = new List <Curve>(); perpParams = new List <double>(); // Divide curve double[] geodParams = previousCurve.DivideByLength(perpStepSize, true); if (geodParams == null) { AddRuntimeMessage(GH_RuntimeMessageLevel.Remark, "No points found on iter" + i); break; } if (geodParams.Length <= 2) { AddRuntimeMessage(GH_RuntimeMessageLevel.Remark, "Not enough points found on iter" + i); break; } // Generate perp geodesics for measurement foreach (double t in geodParams) { // Get curve tangent vector and mesh normal Point3d point = previousCurve.PointAt(t); Vector3d tangent = previousCurve.TangentAt(t); Vector3d normal = mesh.NormalAt(mesh.ClosestMeshPoint(point, 0.0)); // Rotate vector against normals 90 degrees tangent.Rotate(0.5 * Math.PI, normal); // Generate perp geodesic Curve perpGeodesic = MeshGeodesicMethods.getGeodesicCurveOnMesh(mesh, point, tangent, 100).ToNurbsCurve(); // Check for success if (perpGeodesic != null && perpGeodesic.GetLength() > specifiedDistance) { // Divide by specified length double perpT = 0.0; perpGeodesic.LengthParameter(specifiedDistance, out perpT); // Add data to lists perpGeods.Add(perpGeodesic); perpParams.Add(perpT); } } // Clean perp geods of intersections ocurring BEFORE the specified distance var result = CleanPerpGeodesics(perpGeods, perpParams, specifiedDistance); // Assign clean lists perpGeods = result.perpGeodesics; perpParams = result.perpParams; // Break if not enough perpGeods remain if (perpGeods.Count < 6) { AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Not enough perp geodesics where found for iter " + i); break; } //Generate the next piecewise geodesic List <Curve> iterCurves = GeneratePiecewiseGeodesicCurve(mesh, perpParams, perpGeods, 1000, bothDir, 0, threshold, Vector3d.Unset); // Add it to the pattern pattern.AddRange(iterCurves, new GH_Path(i)); // Assign as previous for the next round Curve[] joinedResult = Curve.JoinCurves(iterCurves); // Error check if (joinedResult.Length > 1) { AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "More than 1 curve after Join in iter " + i); break; } //Create points and bisectrix vectors for next round of perp geodesics Point3dList ptList = new Point3dList(); foreach (Curve c in iterCurves) { if (!ptList.Contains(c.PointAtStart)) { ptList.Add(c.PointAtStart); } if (!ptList.Contains(c.PointAtEnd)) { ptList.Add(c.PointAtEnd); } } Debug.WriteLine("ptList Count: " + ptList.Count); // Assign new curve to previous curve Curve joinedCurve = joinedResult[0]; previousCurve = joinedCurve; } // Assign data to output DA.SetDataTree(0, pattern); DA.SetDataList(2, perpGeods); }
public static DataTree<Polyline> makeTiles(Mesh mesh) { DataTree < Polyline> Tree = new DataTree<Polyline>(); for(int i = 0;i < mesh.Faces.Count;i++) { Vector3d ab = new Vector3d (mesh.Vertices[mesh.Faces[i].B] - mesh.Vertices[mesh.Faces[i].A]); Vector3d ac = new Vector3d (mesh.Vertices[mesh.Faces[i].C] - mesh.Vertices[mesh.Faces[i].A]); Point3dList pts = new Point3dList(); pts.Add(mesh.Vertices[mesh.Faces[i].A]); pts.Add(mesh.Vertices[mesh.Faces[i].C]); pts.Add(mesh.Vertices[mesh.Faces[i].B]); Polyline edge = new Polyline(pts); Tree.Add(edge); } return Tree; }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { Point3dList points = new Point3dList(); // Point3dList is from the Collections class, we add a new variable points then initialize it and add // empty array Result commandres; //calls class Point3dList and initializes a new empty array with the name 'points' while (true) //make an infinite loop. every time we click on screen we will create a point which will // be added to the document and the screen will be refreshed. it happens fast!! { var gp = new GetPoint(); //prompt user string prompt; prompt = "set point(s) by click"; gp.SetCommandPrompt(prompt); //set up what to do with the result var res = gp.Get(); //get function returns a really cool type of enumeration // https://developer.rhino3d.com/api/RhinoCommon/html/T_Rhino_Input_GetResult.htm if (res == GetResult.Point) //using Rhino.Input, double equal sign is necessary... { doc.Objects.AddPoint(gp.Point()); //adds a point object to the document to object table doc.Views.Redraw(); //refreshes the views points.Add(gp.Point()); // add the point to our points array declared above commandres = Result.Success; } else if (res == GetResult.Nothing) { commandres = Result.Failure; break; } else { commandres = Result.Cancel; break; } } RhinoApp.WriteLine("The user drew {0} point(s) successfully", points.Count.ToString()); // access the points array and cast it to a string, outside the function so that it will only // show how many ponints you've drawn when the function is complete. return(Result.Success); }
/// <summary> /// Removes duplicate/invalid/tiny curves and outputs the cleaned list, a list of unique nodes and a list of node pairs. /// </summary> public static List<Curve> CleanNetwork(List<Curve> inputStruts, double tol, out Point3dList nodes, out List<IndexPair> nodePairs) { nodes = new Point3dList(); nodePairs = new List<IndexPair>(); var struts = new List<Curve>(); // Loop over list of struts for (int i = 0; i < inputStruts.Count; i++) { Curve strut = inputStruts[i]; // Unitize domain strut.Domain = new Interval(0, 1); // Minimum strut length (if user defined very small tolerance, use 100*rhinotolerance) double minLength = Math.Max(tol, 100*RhinoDoc.ActiveDoc.ModelAbsoluteTolerance); // If strut is invalid, ignore it if (strut == null || !strut.IsValid || strut.IsShort(minLength)) { continue; } Point3d[] pts = new Point3d[2] { strut.PointAtStart, strut.PointAtEnd }; List<int> nodeIndices = new List<int>(); // Loop over end points of strut // Check if node is already in nodes list, if so, we find its index instead of creating a new node for (int j = 0; j < 2; j++) { Point3d pt = pts[j]; // Find closest node to current pt int closestIndex = nodes.ClosestIndex(pt); // If node already exists (within tolerance), set the index if (nodes.Count != 0 && pt.EpsilonEquals(nodes[closestIndex], tol)) { nodeIndices.Add(closestIndex); } // If node doesn't exist else { // Update lookup list nodes.Add(pt); nodeIndices.Add(nodes.Count - 1); } } // We must ignore duplicate struts bool isDuplicate = false; IndexPair nodePair = new IndexPair(nodeIndices[0], nodeIndices[1]); int dupIndex = nodePairs.IndexOf(nodePair); // dupIndex equals -1 if nodePair not found, i.e. if it doesn't equal -1, a match was found if (nodePairs.Count != 0 && dupIndex != -1) { // Check the curve midpoint to make sure it's a duplicate Curve testStrut = struts[dupIndex]; Point3d ptA = strut.PointAt(0.5); Point3d ptB = testStrut.PointAt(0.5); if (ptA.EpsilonEquals(ptB, tol)) isDuplicate = true; } // So we only create the strut if it doesn't exist yet (check nodePairLookup list) if (!isDuplicate) { // Update the lookup list nodePairs.Add(nodePair); strut.Domain = new Interval(0, 1); struts.Add(strut); } } return struts; }
/// <summary> /// Default constructor. /// </summary> public UnitCell() { m_nodes = new Point3dList(); m_nodePairs = new List<IndexPair>(); m_nodePaths = new List<int[]>(); }
/// <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) { int iterations = 3; List <Point3d> iPoints = new List <Point3d>(); GridVectors = new List <Vector3d>(); roadDensity = 0; double blockWidth = 0; List <Curve> outputCurves = new List <Curve>(); DA.GetDataList(0, iPoints); DA.GetDataList(1, GridVectors); DA.GetData(2, ref GridFirstPoint); DA.GetData(3, ref GridLastPoint); DA.GetData(4, ref boundary); DA.GetData(5, ref roadDensity); DA.GetData(6, ref angle); DA.GetData(7, ref iterations); DA.GetData(8, ref step); // step = blockWidth; // roadDensity = step - 10; gridRes = (int)Math.Sqrt(GridVectors.Count) - 1; pointCloud = new Point3dList(); int sign = 1; Vector3d prevTensor = new Vector3d(0, 1, 0); Point3d nextPt = new Point3d(); Vector3d nextTensor = new Vector3d(); List <Point3d> currPointList = new List <Point3d>(); List <Point3d> prevPointList = new List <Point3d>(); for (int i = 0; i < iterations; i++) { List <Curve> currCurves = new List <Curve>(); for (int j = 0; j < iPoints.Count; j++) // J ======= iPoints { sign = 1; currPointList.Clear(); prevPointList.Clear(); for (int k = 0; k < 2; k++) { prevPointList = new List <Point3d>(currPointList); currPointList.Clear(); // prevTensor = new Vector3d((i + 1) % 2, (i) % 2, 0); prevTensor = new Vector3d(0, 0, 0); if (GetTensor(iPoints[j], prevTensor) != Vector3d.Unset) { nextPt = iPoints[j] + sign * GetTensor(iPoints[j], prevTensor); currPointList.Add(iPoints[j]); prevTensor = GetTensor(iPoints[j], prevTensor); } int f = 0; while (CheckPt(nextPt) && f < 100) { currPointList.Add(nextPt); nextTensor = GetTensor(currPointList[currPointList.Count - 1], prevTensor); nextPt = currPointList[currPointList.Count - 1] + sign * nextTensor; f++; prevTensor = nextTensor; } double t = 0; boundary.ClosestPoint((currPointList[currPointList.Count - 1]), out t, step + 5); if (boundary.Contains(nextPt) == PointContainment.Outside && CheckPt(currPointList[currPointList.Count - 1])) { currPointList.Add(boundary.PointAt(t)); } else { if (pointCloud.Count > 0) { Point3d pt = pointCloud[pointCloud.ClosestIndex(nextPt)]; // if ((pt.DistanceTo(nextPt) <= roadDensity) && f > 0) currPointList.Add(pt); } } outputCurves.Add(new PolylineCurve(currPointList)); currCurves.Add(new PolylineCurve(currPointList)); sign = -1; } pointCloud.AddRange(currPointList); pointCloud.AddRange(prevPointList); } iPoints.Clear(); foreach (PolylineCurve curve in currCurves) { if (curve != null && curve.GetLength() > 0.1) { // if (curve.DivideEquidistant(blockWidth) != null) // iPoints.AddRange(new List<Point3d>(curve.DivideEquidistant(blockWidth))); List <Point3d> points = new List <Point3d>(); for (int q = 0; q < curve.PointCount; q++) { points.Add(curve.Point(q)); } iPoints.AddRange(points); } } angle += 90; } DA.SetDataList(0, outputCurves); }
DataTree<Object> GetStepTree(Mesh terrainMesh, List<double> contourZList, DataTree<Curve> contourTree, List<Brep> brepList) { DataTree<Object> stepTree = new DataTree<Object>(); Plane basePlane = Plane.WorldXY; basePlane.OriginZ = terrainMesh.GetBoundingBox(true).Min.Z; // For each contour-plane for (int i = 0; i < contourTree.BranchCount; i++) { // create higher-Z pt list Point3dList winPtList = new Point3dList(); foreach (Curve contourCrv in contourTree.Branches[i]) { Plane frm; double t; contourCrv.NormalizedLengthParameter(0.5, out t); contourCrv.FrameAt(t, out frm); frm.Transform(Rhino.Geometry.Transform.PlanarProjection(basePlane)); Point3d samplePt0, samplePt1; samplePt0 = frm.Origin; samplePt1 = frm.Origin; samplePt0 += doc.ModelAbsoluteTolerance * frm.YAxis; samplePt1 -= doc.ModelAbsoluteTolerance * frm.YAxis; Ray3d ray0 = new Ray3d(samplePt0, Vector3d.ZAxis); Ray3d ray1 = new Ray3d(samplePt1, Vector3d.ZAxis); double rayParam0 = Rhino.Geometry.Intersect.Intersection.MeshRay(terrainMesh, ray0); double rayParam1 = Rhino.Geometry.Intersect.Intersection.MeshRay(terrainMesh, ray1); winPtList.Add(((rayParam0 > rayParam1) ? samplePt0 : samplePt1)); } // For each splitted region in contour-plane foreach (BrepFace brepFace in brepList[i].Faces) { Brep testBrep = brepFace.DuplicateFace(false); foreach (Point3d pt in winPtList) { LineCurve testRay = new LineCurve(new Line(pt, Vector3d.ZAxis, 1000)); Point3d[] outPts; Curve[] outCrvs; bool ix = Rhino.Geometry.Intersect.Intersection.CurveBrep(testRay, testBrep, doc.ModelAbsoluteTolerance, out outCrvs, out outPts); if (outPts.Length != 0) { stepTree.Add(testBrep, new GH_Path(i)); break; } } } } return stepTree; }