private static List <Polyline> DrawCorridor(List <Point3d> anchors, List <Line> mainAxis) { List <Polyline> corridor = new List <Polyline>(); if (anchors.Count < 2) { return(null); } List <Rectangle3d> rectList = new List <Rectangle3d>(); for (int i = 0; i < anchors.Count - 1; i++) { Rectangle3d tempRect = RectangleTools.DrawP2PRect(anchors[i], anchors[i + 1], CorridorDimension.OneWayWidth); rectList.Add(tempRect); } if (rectList.Count > 1) { Curve intersected = rectList[0].ToNurbsCurve(); for (int i = 0; i < rectList.Count - 1; i++) { List <Curve> unionCurves = new List <Curve>(); unionCurves.Add(intersected); unionCurves.Add(rectList[i + 1].ToNurbsCurve()); intersected = Curve.CreateBooleanUnion(unionCurves)[0]; } corridor.Add(CurveTools.ToPolyline(intersected)); } return(corridor); }
private static List <Polyline> RemoveOverlapSeg(Polyline trimmee, Polyline trimmer) { List <Polyline> trimmed = new List <Polyline>(); List <Curve> memberToJoin = new List <Curve>(); Curve trimmerCrv = trimmer.ToNurbsCurve(); List <Curve> trimmeeSeg = trimmee.ToNurbsCurve().DuplicateSegments().ToList(); foreach (Curve i in trimmeeSeg) { if (!CurveTools.IsOverlap(i, trimmerCrv, 0.005)) { memberToJoin.Add(i); } } List <Curve> joinedCrvs = Curve.JoinCurves(memberToJoin, 0.5, true).ToList(); foreach (Curve i in joinedCrvs) { trimmed.Add(CurveTools.ToPolyline(i)); } if (trimmed.Count == 0) { return(new List <Polyline>()); } return(trimmed); }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { RhinoApp.WriteLine("안녕하세요 방만드는기계 입니다."); // Polyline outline = new Polyline(); Polyline coreLine = new Polyline(); Polyline landing = new Polyline(); GetObject getPolyline = new GetObject(); getPolyline.SetCommandPrompt("외곽선,코어,랜딩 입력해주세요"); getPolyline.GeometryFilter = Rhino.DocObjects.ObjectType.Curve; getPolyline.GeometryAttributeFilter = GeometryAttributeFilter.ClosedCurve; getPolyline.SubObjectSelect = false; getPolyline.GetMultiple(3, 0); if (getPolyline.CommandResult() != Result.Success) { RhinoApp.WriteLine("달라고!"); return(getPolyline.CommandResult()); } else { RhinoApp.WriteLine("입력받았습니다."); } if (null == getPolyline.Object(0).Curve()) { RhinoApp.WriteLine("없잖아!"); return(getPolyline.CommandResult()); } List <Polyline> testPoly = new List <Polyline>(); foreach (var i in getPolyline.Objects()) { testPoly.Add(CurveTools.ToPolyline(i.Curve())); } outline = testPoly[0]; coreLine = testPoly[1]; landing = testPoly[2]; List <Polyline> rooms = Debugger.DebugRoom(outline, coreLine, landing); foreach (Polyline i in rooms) { doc.Objects.AddCurve(i.ToNurbsCurve()); } doc.Views.Redraw(); RhinoApp.WriteLine("최선을 다했습니다만..."); return(Result.Success); }
private void btnOutline_Click(object sender, EventArgs e) { curveBox.outlines = null; var dissolvedCurves = new List <Curve>(CurveTools.Dissolve(curveBox.curves)); //var cleanedCurves = new List<Curve>(CurveTools.RemoveOrphanedCurves(dissolvedCurves)); var curves = new CurveCollection(dissolvedCurves).BreakApart(); curveBox.curves = new CurveCollection(dissolvedCurves); curveBox.outlines = new CurveCollection(curves.GetOutlines()); curveBox.Invalidate(); }
private static List <Polyline> GetBooleanDifference(Polyline outline, Polyline coreUnion) { List <Polyline> trimmedOutline = new List <Polyline>(); List <Curve> trimmed = Curve.CreateBooleanDifference(outline.ToNurbsCurve(), coreUnion.ToNurbsCurve()).ToList(); foreach (Curve i in trimmed) { trimmedOutline.Add(CurveTools.ToPolyline(i)); } return(trimmedOutline); }
private static List <Polyline> DrawCorridor(List <Point3d> anchors, List <Line> baseAxis, double subLength) { List <Polyline> corridor = new List <Polyline>(); Rectangle3d subCorridor = RectangleTools.DrawP2PRect(anchors[0], anchors[1], subLength, CorridorDimension.TwoWayWidth); Rectangle3d mainCorridor = RectangleTools.DrawP2PRect(anchors[1], anchors[2], CorridorDimension.TwoWayWidth, subLength); List <Curve> forUnion = new List <Curve>(); forUnion.Add(subCorridor.ToNurbsCurve()); forUnion.Add(mainCorridor.ToNurbsCurve()); corridor.Add(CurveTools.ToPolyline(Curve.CreateBooleanUnion(forUnion)[0])); return(corridor); }
//process method private List <Room> MakeRooms(List <LabeledOutline> outlinelabels, List <List <Room> > allocatedRoom) { //draw outline. List <Polyline> roomOutlines = new List <Polyline>(); for (int i = 0; i < outlinelabels.Count; i++) { roomOutlines.AddRange( DrawRoomAtEachPart(outlinelabels[i], allocatedRoom[i].Select(n => n.Area).ToList())); } //merge smallRoom. //tolerance 문제 있을듯 if (roomOutlines.Count > 1 && roomOutlines.Last().GetArea() < Dimensions.MinRoomArea) { Curve lastRoom = roomOutlines.Last().ToNurbsCurve(); roomOutlines.RemoveAt(roomOutlines.Count - 1); Curve preLastRoom = roomOutlines.Last().ToNurbsCurve(); roomOutlines.RemoveAt(roomOutlines.Count - 1); Curve[] merged = Curve.CreateBooleanUnion(new List <Curve> { lastRoom, preLastRoom }); merged.OrderByDescending(n => n.GetArea()); roomOutlines.Add(CurveTools.ToPolyline(merged.First())); } //assign to RoomClass List <Room> rooms = new List <Room>(); List <Room> outlineLackedRoom = new List <Room>(); allocatedRoom.ForEach(n => outlineLackedRoom.AddRange(n)); for (int i = 0; i < roomOutlines.Count; i++) { Room currentRoom = outlineLackedRoom[i]; currentRoom.Outline = roomOutlines[i]; currentRoom.Area = roomOutlines[i].GetArea(); rooms.Add(currentRoom); } return(rooms); }
//method private static Polyline GetCoreUnion(Core core, List <Polyline> corridor) { List <Curve> coreAndCorridor = new List <Curve>(); coreAndCorridor.Add(core.Outline.ToNurbsCurve()); foreach (Polyline i in corridor) { coreAndCorridor.Add(i.ToNurbsCurve()); } if (coreAndCorridor.Count == 1) { return(core.Outline); } Curve union = Curve.CreateBooleanUnion(coreAndCorridor)[0]; return(CurveTools.ToPolyline(union)); }
//this checks if initial data is valid private bool Setup(List <Line> lines) { if (!SetupPointGroups(lines)) { return(false); } //setup control handles Vector2D center1 = CurveTools.GetPointOnLine(pointGroup1[0], pointGroup1[segmentsCount - 1], 0.5f); Vector2D center2 = CurveTools.GetPointOnLine(pointGroup2[0], pointGroup2[segmentsCount - 1], 0.5f); Vector2D loc1 = GetHandleLocation(pointGroup1[0], pointGroup1[segmentsCount - 1], center2); Vector2D loc2 = GetHandleLocation(pointGroup2[0], pointGroup2[segmentsCount - 1], center1); ControlHandle ch1 = new ControlHandle { ControlledPoint = pointGroup1[0], RelativePosition = loc1 }; ControlHandle ch2 = new ControlHandle { ControlledPoint = pointGroup2[0], RelativePosition = loc2 }; ControlHandle ch3 = new ControlHandle { ControlledPoint = pointGroup1[segmentsCount - 1], RelativePosition = loc1 }; ControlHandle ch4 = new ControlHandle { ControlledPoint = pointGroup2[segmentsCount - 1], RelativePosition = loc2 }; ch1.Pair = ch3; ch2.Pair = ch4; ch3.Pair = ch1; ch4.Pair = ch2; controlHandles = new[] { ch1, ch2, ch3, ch4 }; //setup relative segments lengths relLenGroup1 = GetRelativeLengths(pointGroup1); relLenGroup2 = GetRelativeLengths(pointGroup2); return(true); }
private static List <List <RoomLine> > LabelUnionSeg(List <Polyline> trimmedUnion, Core core, List <Polyline> corridor) { List <List <RoomLine> > labeledCore = new List <List <RoomLine> >(); //label decider setting Curve coreCrv = core.Outline.ToNurbsCurve(); List <Curve> corridorCrv = new List <Curve>(); corridorCrv.Add(core.Landing.ToNurbsCurve()); foreach (Polyline i in corridor) { corridorCrv.Add(i.ToNurbsCurve()); } //label foreach (Polyline i in trimmedUnion) { List <Line> unlabeledSeg = i.GetSegments().ToList(); List <RoomLine> currentPolyLabels = new List <RoomLine>(); foreach (Line j in unlabeledSeg) { Curve jCrv = j.ToNurbsCurve(); if (CurveTools.IsOverlap(jCrv, corridorCrv, 0.005)) { currentPolyLabels.Add(new RoomLine(j, LineType.Corridor)); } else if (CurveTools.IsOverlap(jCrv, coreCrv, 0.005)) { currentPolyLabels.Add(new RoomLine(j, LineType.Core)); } } labeledCore.Add(currentPolyLabels); } return(labeledCore); }
//mxd public void DrawLine3DFloor(Vector2D start, Vector2D end, ref PixelColor c, PixelColor c2) { Vector2D delta = end - start; float length = delta.GetLength(); if (length < DASH_INTERVAL * 2) { DrawLineSolid((int)start.x, (int)start.y, (int)end.x, (int)end.y, ref c2); } else { float d1 = DASH_INTERVAL / length; float d2 = 1.0f - d1; Vector2D p1 = CurveTools.GetPointOnLine(start, end, d1); Vector2D p2 = CurveTools.GetPointOnLine(start, end, d2); DrawLineSolid((int)start.x, (int)start.y, (int)p1.x, (int)p1.y, ref c2); DrawLineSolid((int)p1.x, (int)p1.y, (int)p2.x, (int)p2.y, ref c); DrawLineSolid((int)p2.x, (int)p2.y, (int)end.x, (int)end.y, ref c2); } }
public static List <Brep> DrawHouse(Household hhp) { double height = Consts.FloorHeight; Curve outline = hhp.GetOutline(); Polyline outPoly = CurveTools.ToPolyline(outline); Brep x = Extrusion.Create(outline, height, true).ToBrep(); x.CapPlanarHoles(1); double windowSide = 300; double windowLow = 300; double windowHeight = 2100; double windowDepth = 200; List <Brep> wins = new List <Brep>(); for (int i = 0; i < hhp.LightingEdge.Count; i++) { //Rhino.RhinoDoc.ActiveDoc.Objects.Add(hhp.LightingEdge[i].ToNurbsCurve()); //var c = hhp.LightingEdge[i].ToNurbsCurve().Trim(CurveEnd.Both, 300); //var p1 = c.PointAtStart + Vector3d.ZAxis * 300; //var p2 = c.PointAtStart + Vector3d.ZAxis * 2400; //var p3 = c.PointAtEnd + Vector3d.ZAxis * 2400; //var p4 = c.PointAtEnd + Vector3d.ZAxis * 300; //Brep[] open = Brep.CreatePlanarBreps(new PolylineCurve(new Point3d[] { p1, p2, p3, p4, p1 })); Line tempLine = hhp.LightingEdge[i]; Point3d midPoint = tempLine.PointAt(0.5); Vector3d windowVec = tempLine.UnitTangent; windowVec.Rotate(Math.PI / 2, Vector3d.ZAxis); midPoint.Transform(Transform.Translation(Vector3d.Multiply(windowVec, 10))); if (hhp.GetOutline().Contains(midPoint) == Rhino.Geometry.PointContainment.Inside) { tempLine.Flip(); } tempLine.Extend(-windowSide, -windowSide); Curve tempCurve = tempLine.ToNurbsCurve(); tempCurve.Translate(Vector3d.Multiply(Vector3d.ZAxis, windowLow)); Point3d pt1 = tempCurve.PointAtStart; Point3d pt2 = tempCurve.PointAtEnd; Point3d pt3 = tempCurve.PointAtEnd; pt3.Transform(Transform.Translation(Vector3d.Multiply(Vector3d.ZAxis, windowHeight))); Point3d pt4 = tempCurve.PointAtStart; pt4.Transform(Transform.Translation(Vector3d.Multiply(Vector3d.ZAxis, windowHeight))); Point3d pt5 = tempCurve.PointAtStart; List <Point3d> windowPoints = new List <Point3d>(); windowPoints.Add(pt1); windowPoints.Add(pt2); windowPoints.Add(pt3); windowPoints.Add(pt4); windowPoints.Add(pt5); Polyline windowPolyline = new Polyline(windowPoints); Curve win = windowPolyline.ToNurbsCurve(); Plane windowPlane; win.TryGetPlane(out windowPlane); Vector3d windowNormal = windowPlane.Normal; Curve windowCurve = win.Duplicate() as Curve; windowCurve.Translate(Vector3d.Multiply(windowNormal, windowDepth)); Surface windowSurface = Surface.CreateExtrusion(windowCurve, Vector3d.Multiply(windowNormal, -windowDepth * 2)); Brep windowBrep = windowSurface.ToBrep(); Brep[] withHolesTemp = x.Split(windowBrep, 1); if (withHolesTemp.Length != 0) { x = withHolesTemp[0]; } Curve duplicatedWindowCurve = (win.Duplicate() as Curve); duplicatedWindowCurve.Transform(Transform.Translation(windowNormal * (windowDepth - 100))); Curve windowCurveBottom = duplicatedWindowCurve.DuplicateSegments()[0]; Curve heightCurve = duplicatedWindowCurve.DuplicateSegments()[1]; wins.AddRange(DrawWindowAll(windowCurveBottom, heightCurve.GetLength(), false)); Curve[] tempLoftBase = { win, duplicatedWindowCurve }; Curve pathCurve = new LineCurve(Point3d.Origin, new Point3d(windowNormal * (-windowDepth + 100))); wins.Add(Brep.JoinBreps(Brep.CreateFromLoft(tempLoftBase, Point3d.Unset, Point3d.Unset, LoftType.Normal, false), 0)[0]); } //1. 양쪽에서 300씩 , 위400 아래300 사각형.빵꾸. 안쪽으로 200 //->창틀 //2. 사방 30씩, 안쪽으로 100 //->창문와꾸 //3. 창 안쪽에서 20, 창문와꾸 30, 바깥쪽50 ,길이 1200 * 2 //4. ㅊ //Brep w1 = Brep.create hhp.LightingEdge[0] wins.Add(x); return(wins); }
private void Update() { if (renderer.StartOverlay(true)) { snaptogrid = General.Interface.ShiftState ^ General.Interface.SnapToGrid; PixelColor linesColor = snaptogrid ? General.Colors.Selection : General.Colors.Highlight; //draw curves curves = new List <Vector2D[]>(); for (int i = 0; i < segmentsCount; i++) { Vector2D cp1 = CurveTools.GetPointOnLine(controlHandles[0].Position, controlHandles[2].Position, relLenGroup1[i]); Vector2D cp2 = CurveTools.GetPointOnLine(controlHandles[1].Position, controlHandles[3].Position, relLenGroup2[i]); curves.Add(CurveTools.GetCubicCurve(pointGroup1[i], pointGroup2[i], cp1, cp2, form.Subdivisions)); for (int c = 1; c < curves[i].Length; c++) { renderer.RenderLine(curves[i][c - 1], curves[i][c], LINE_THICKNESS, linesColor, true); } } //draw connecting lines if (form.Subdivisions > 1) { for (int i = 1; i < segmentsCount; i++) { for (int c = 1; c < form.Subdivisions; c++) { renderer.RenderLine(curves[i - 1][c], curves[i][c], LINE_THICKNESS, linesColor, true); } } } //draw vertices float vsize = (renderer.VertexSize + 1.0f) / renderer.Scale; foreach (Vector2D[] points in curves) { for (int i = 1; i < points.Length - 1; i++) { renderer.RenderRectangleFilled(new RectangleF(points[i].x - vsize, points[i].y - vsize, vsize * 2.0f, vsize * 2.0f), linesColor, true); } } //draw handle lines renderer.RenderLine(pointGroup1[0], controlHandles[0].Position, LINE_THICKNESS, handleColor, true); renderer.RenderLine(pointGroup2[0], controlHandles[1].Position, LINE_THICKNESS, handleColor, true); renderer.RenderLine(pointGroup1[segmentsCount - 1], controlHandles[2].Position, LINE_THICKNESS, handleColor, true); renderer.RenderLine(pointGroup2[segmentsCount - 1], controlHandles[3].Position, LINE_THICKNESS, handleColor, true); //draw handles float gripsize = GRIP_SIZE / renderer.Scale; for (int i = 0; i < 4; i++) { RectangleF handleRect = new RectangleF(controlHandles[i].Position.x - gripsize * 0.5f, controlHandles[i].Position.y - gripsize * 0.5f, gripsize, gripsize); renderer.RenderRectangleFilled(handleRect, General.Colors.Background, true); renderer.RenderRectangle(handleRect, 2, General.Colors.Highlight, true); } renderer.Finish(); } renderer.Present(); }
protected override void Update() { PixelColor stitchcolor = General.Colors.Highlight; PixelColor losecolor = General.Colors.Selection; snaptocardinaldirection = General.Interface.ShiftState && General.Interface.AltState; snaptogrid = snaptocardinaldirection || General.Interface.ShiftState ^ General.Interface.SnapToGrid; snaptonearest = General.Interface.CtrlState ^ General.Interface.AutoMerge; DrawnVertex curp = GetCurrentPosition(); float vsize = (renderer.VertexSize + 1.0f) / renderer.Scale; // Update label positions (mxd) if (labels.Count > 0) { // Update labels for already drawn lines for (int i = 0; i < labels.Count - 1; i++) { labels[i].Move(points[i].pos, points[i + 1].pos); } // Update label for active line labels[labels.Count - 1].Move(points[points.Count - 1].pos, curp.pos); } // Render drawing lines if (renderer.StartOverlay(true)) { // Go for all points to draw lines if (points.Count > 0) { //update curve List <Vector2D> verts = new List <Vector2D>(); for (int i = 0; i < points.Count; i++) { verts.Add(points[i].pos); } if (curp.pos != verts[verts.Count - 1]) { verts.Add(curp.pos); } curve = CurveTools.CurveThroughPoints(verts, 0.5f, 0.75f, segmentlength); // Render lines for (int i = 1; i < curve.Shape.Count; i++) { // Determine line color PixelColor c = snaptonearest ? stitchcolor : losecolor; // Render line renderer.RenderLine(curve.Shape[i - 1], curve.Shape[i], LINE_THICKNESS, c, true); } //render "inactive" vertices for (int i = 1; i < curve.Shape.Count - 1; i++) { // Determine vertex color PixelColor c = !snaptonearest ? stitchcolor : losecolor; // Render vertex renderer.RenderRectangleFilled(new RectangleF(curve.Shape[i].x - vsize, curve.Shape[i].y - vsize, vsize * 2.0f, vsize * 2.0f), c, true); } } if (points.Count > 0) { // Render vertices for (int i = 0; i < points.Count; i++) { // Determine vertex color PixelColor c = points[i].stitch ? stitchcolor : losecolor; // Render vertex renderer.RenderRectangleFilled(new RectangleF(points[i].pos.x - vsize, points[i].pos.y - vsize, vsize * 2.0f, vsize * 2.0f), c, true); } } // Determine point color PixelColor color = snaptonearest ? stitchcolor : losecolor; // Render vertex at cursor renderer.RenderRectangleFilled(new RectangleF(curp.pos.x - vsize, curp.pos.y - vsize, vsize * 2.0f, vsize * 2.0f), color, true); // Render labels renderer.RenderText(labels.ToArray()); //Render info label Vector2D start = new Vector2D(mousemappos.x + (32 / renderer.Scale), mousemappos.y - (16 / renderer.Scale)); Vector2D end = new Vector2D(mousemappos.x + (96 / renderer.Scale), mousemappos.y); hintlabel.Move(start, end); hintlabel.Text = "SEG LEN: " + segmentlength; renderer.RenderText(hintlabel.TextLabel); // Done renderer.Finish(); } // Done renderer.Present(); }
private static PartitionParam DrawAtMultiFoldOutline(PartitionParam param, double targetArea, List <Point3d> outlineVertex) { Line mainLine = GetMainLine(param, outlineVertex); List <Point3d> canMakePerpVertex = new List <Point3d>(); Vector3d mainAlign = mainLine.UnitTangent; Vector3d mainPerp = VectorTools.RotateVectorXY(mainAlign, Math.PI / 2); Point3d origin = param.OriginPost.Point; bool isMainAlignSameAsPostNormal = mainAlign.IsParallelTo(param.OriginPost.BaseLine.UnitNormal, 0.005) == 1; if (!isMainAlignSameAsPostNormal) { int originIndex = param.OutlineLabel.Core.FindIndex (i => i.PureLine == param.OriginPost.BasePureLine); param.OriginPost = new PartitionOrigin(origin, param.OutlineLabel.Core[originIndex - 1]); mainPerp = VectorTools.RotateVectorXY(mainAlign, -Math.PI / 2); } int lastVertexIndex = outlineVertex.Count - 1; for (int i = 1; i < lastVertexIndex; i++) { Vector3d toPreVector = new Vector3d(outlineVertex[i - 1] - outlineVertex[i]); Vector3d toPostVector = new Vector3d(outlineVertex[i + 1] - outlineVertex[i]); Vector3d toMainVector = -mainPerp; if (IsBetweenVector(toPreVector, toPostVector, toMainVector)) { canMakePerpVertex.Add(outlineVertex[i]); } } //SeivePerpVertex List <Point3d> finalVertex = new List <Point3d>(); foreach (Point3d i in outlineVertex) { Line toBaseLine = PCXTools.PCXByEquationStrict(i, CurveTools.ToPolyline(mainLine.ToNurbsCurve()), -mainPerp); Line toOutline = PCXTools.PCXByEquationStrict(toBaseLine.PointAt(1), param.OutlineLabel.Pure, mainPerp); if (toOutline.PointAt(1).DistanceTo(i) < 0.5) { finalVertex.Add(i); } } //DrawAtEachVertex List <PartitionParam> outputCandidate = new List <PartitionParam>(); foreach (Point3d i in finalVertex) { Line toBaseLine = PCXTools.PCXByEquationStrict(i, CurveTools.ToPolyline(mainLine.ToNurbsCurve()), -mainPerp); Point3d tempAnchor = toBaseLine.PointAt(1); Line toOutline = PCXTools.PCXByEquationStrict(tempAnchor, param.OutlineLabel.Pure, mainPerp); if (toOutline.PointAt(1).DistanceTo(i) > 0.5) { continue; } List <RoomLine> tempPartition = new List <RoomLine>(); tempPartition.Add(new RoomLine(new Line(origin, tempAnchor), LineType.Inner)); tempPartition.Add(new RoomLine(new Line(tempAnchor, i), LineType.Inner)); PartitionParam tempParam = new PartitionParam(param); tempParam.PartitionPost = new Partition(tempPartition, param.OriginPost); outputCandidate.Add(tempParam); } outputCandidate.Add(PartitionMaker.DrawOrtho(param)); //TestCandidate //나중에 수정.. 지금은 면적일치정도로만.. Plane cornerPlane = new Plane(origin, mainAlign, mainPerp); CornerComparer comparer = new CornerComparer(); List <PartitionParam> seived = comparer.Seive(outputCandidate, targetArea, cornerPlane); return(seived[0]); }