public static void CompositeCurveMeshing(Model model) { MainWindow.SetDisplayMode(model, displayType.Shaded); CompositeCurve outer = new CompositeCurve(); outer.CurveList.Add(new Line(0, 0, 10, 0)); outer.CurveList.Add(new Line(10, 0, 10, 6)); outer.CurveList.Add(new Line(10, 6, 0, 6)); outer.CurveList.Add(new Line(0, 6, 0, 0)); CompositeCurve inner1 = new CompositeCurve(); inner1.CurveList.Add(new Line(2, 2, 6, 2)); inner1.CurveList.Add(new Line(6, 2, 2, 3)); inner1.CurveList.Add(new Line(2, 3, 2, 2)); CompositeCurve inner2 = new CompositeCurve(); inner2.CurveList.Add(new Circle(8, 4, 0, 1)); CompositeCurve inner3 = new CompositeCurve(); inner3.CurveList.Add(new Circle(6, 4, 0, .75)); Region reg = new Region(outer, inner1, inner2, inner3); Mesh m = UtilityEx.Triangulate(reg, .15); model.Entities.Add(m, Color.Salmon); }
private void delaunayToolStripMenuItem_Click(object sender, EventArgs e) { int rows = 100; int cols = 100; Point3D[] points = new Point3D[rows * cols]; int min = -2; int max = 2; int minxy = -1000; int maxxy = 1000; Random random = new Random(); int index = 0; for (int i = 0; i < rows; ++i) { for (int j = 0; j < cols; ++j) { points[index] = new Point3D(random.Next(minxy, maxxy), random.Next(minxy, maxxy), random.Next(min, max)); index++; } } Mesh tin = UtilityEx.Triangulate(points, Mesh.natureType.RichSmooth); if (tin != null) { model1.Entities.Add(tin, Color.YellowGreen); } }
protected override bool AllVerticesInScreenPolygon(ScreenPolygonParams data) { // Computes the triangles that are completely enclosed to the screen polygon if (vp.processVisibleOnly && !Selected) { return(false); } SelectedSubItems = new List <int>(); for (int i = 0; i < Triangles.Length; i++) { var verts = GetTriangleVertices(Triangles[i]); if (UtilityEx.AllVerticesInScreenPolygon(data, verts, 3)) { SelectedSubItems.Add(i); } } UpdateCompileSelection(); return(false); }
// Read each line in sequence but first line is >30; private List <Line> ReadDxfInSeq() { var listOfLines = Entities.OfType <Line>().ToList(); if (listOfLines.Count == 0) { MessageBox.Show("Profile line are not availabel.Check std", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return(null); } var firstLine = listOfLines.First(line => line.StartPoint.Equals(Point3D.Origin)); var points = Utilities.GetVertices(listOfLines); var clockwise = Utility.IsOrientedClockwise(points); // IsClockwisePolygon(points); ICurve curve = UtilityEx.SmartAdd(listOfLines.OfType <ICurve>().ToList(), true); if (!clockwise) { listOfLines.Reverse(); } // 0,0 clockwise var allSeqLines = GetContinuity(firstLine, listOfLines); // in clockwise manner var lastLine = allSeqLines[0]; if (lastLine.Length() > 30) // to start from 0,0. { allSeqLines.RemoveAt(0); allSeqLines.Add(lastLine); } OrderEntityList(allSeqLines); return(allSeqLines); }
protected override bool AllVerticesInScreenPolygon(ScreenPolygonParams data) { // Computes the lines that are completely enclosed to the screen polygon if (vp.processVisibleOnly && !Selected) { return(false); } SelectedSubItems = new List <int>(); for (int i = 0; i < Lines.Length; i++) { IndexLine line = Lines[i]; if (UtilityEx.AllVerticesInScreenPolygon(data, new List <Point3D>() { Vertices[line.V1], Vertices[line.V2] }, 2)) { SelectedSubItems.Add(i); } } return(false); }
public static void TerrainTriangulation(Model model) { MainWindow.SetBackgroundStyleAndColor(model); int sideCount = 100; int len = sideCount * sideCount; Point3D[] pts = new Point3D[len]; Random rand = new Random(3); for (int j = 0; j < sideCount; j++) { for (int i = 0; i < sideCount; i++) { double x = rand.NextDouble() * sideCount; double y = rand.NextDouble() * sideCount; double z = 0; double _x = x / 2 - 15; double _y = y / 2 - 15; double den = Math.Sqrt(_x * _x + _y * _y); if (den != 0) { z = 10 * Math.Sin(Math.Sqrt(_x * _x + _y * _y)) / den; } int R = (int)(255 * (z + 2) / 12); int B = (int)(2.55 * y); Utility.LimitRange <int>(0, ref R, 255); Utility.LimitRange <int>(0, ref B, 255); PointRGB pt = new PointRGB(x, y, z, (byte)R, 255, (byte)B); pts[i + j * sideCount] = pt; } } Mesh m = UtilityEx.Triangulate(pts); model.Entities.Add(m); Plane pln = new Plane(new Point3D(0, 20, 20), new Vector3D(20, -30, 10)); PlanarEntity pe = new PlanarEntity(pln, 25); model.Entities.Add(pe, Color.Magenta); ICurve[] curves = m.Section(pln, 0); foreach (Entity ent in curves) { model.Entities.Add(ent); } }
void MakeFemMeshSample() { Line l1 = new Line(0, 0, 100, 0); Line l2 = new Line(100, 0, 100, 30); Line l3 = new Line(100, 30, 80, 30); Arc a1 = new Arc(80, 50, 0, 20, Utility.DegToRad(180), Utility.DegToRad(270)); Line l4 = new Line(60, 50, 60, 80); Line l5 = new Line(60, 80, 30, 80); Line l6 = new Line(30, 80, 30, 31); Arc a2 = new Arc(29, 31, 0, 1, Utility.DegToRad(270), Utility.DegToRad(360)); Line l7 = new Line(29, 30, 26, 30); Arc a3 = new Arc(26, 31, 0, 1, Utility.DegToRad(180), Utility.DegToRad(270)); Line l8 = new Line(25, 31, 25, 80); Line l9 = new Line(25, 80, 15, 80); Line l10 = new Line(15, 80, 15, 31); Arc a4 = new Arc(14, 31, 0, 1, Utility.DegToRad(270), Utility.DegToRad(360)); Line l11 = new Line(14, 30, 11, 30); Arc a5 = new Arc(11, 31, 0, 1, Utility.DegToRad(180), Utility.DegToRad(270)); Line l12 = new Line(10, 31, 10, 80); Line l13 = new Line(10, 80, 0, 80); Line l14 = new Line(0, 80, 0, 0); Circle c1 = new Circle(20, 15, 0, 5); Circle c2 = new Circle(35, 15, 0, 5); Circle c3 = new Circle(50, 15, 0, 5); Circle c4 = new Circle(65, 15, 0, 5); devDept.Eyeshot.Entities.Region reg = new devDept.Eyeshot.Entities.Region(new ICurve[] { new CompositeCurve(l1, l2, l3, l4, l5, l6, l7, l8, l9, l10, l11, l12, l13, l14, a1, a2, a3, a4, a5), c1, c2, c3, c4 }, Plane.XY); Mesh m = UtilityEx.Triangulate(reg, 3); Material copper = Material.Copper; copper.ElementThickness = 6; copper.ElementType = elementType.PlaneStress; FemMesh fMesh = m.ConvertToFemMesh(copper, true); fMesh.FixAll(new Point3D(0, 0), new Point3D(100, 0), .1); fMesh.SetForce(new Point3D(0, 70), new Point3D(50, 70), .1, new Vector3D(-1, 0, 0)); model1.Entities.Add(fMesh); model1.Invalidate(); Solver s1 = new Solver(fMesh); model1.DoWork(s1); model1.Invalidate(); fMesh.PlotMode = FemMesh.plotType.U; fMesh.NodalAverages = true; fMesh.ComputePlot(model1, model1.ActiveViewport.Legends[0]); model1.ZoomFit(); }
protected override bool AllVerticesInFrustum(FrustumParams data) { if (entityNature == entityNatureType.Wire) { return(UtilityEx.AllVerticesInFrustum(data, wireVertices, wireVertices.Length)); } return(base.AllVerticesInFrustum(data)); }
protected override bool ComputeBoundingBox(TraversalParams data, out Point3D boxMin, out Point3D boxMax) { if (entityNature == entityNatureType.Wire) { UtilityEx.ComputeBoundingBox(data.Transformation, wireVertices, out boxMin, out boxMax); } else { base.ComputeBoundingBox(data, out boxMin, out boxMax); } return(true); }
private Brep OffsetRevolvedShell(List <Surface> surfs, double thickness, bool flipNorm, bool inner, Point3D relOrigin) { var hasOffset = Math.Abs(thickness) > 0.0; var outerInner = GetOuterInnerSurfaces(surfs, relOrigin); var bound = (inner) ? outerInner.Item1 : outerInner.Item2; var curves = bound.Section(Plane.XZ, 0.0001).ToList(); curves = UtilityEx.GetConnectedCurves(curves, 0.0001).ToList(); var flat = curves.Any(c => c.IsInPlane(Plane.XY, 0.0001)); var curve = (flat) ? curves.OrderByDescending(c => c.StartPoint.DistanceTo(Point3D.Origin)).Last() : curves.OrderByDescending(c => c.StartPoint.DistanceTo(Point3D.Origin)).First(); var direction = 1.0; if (inner) { curve.Reverse(); direction *= -1.0; } if ((curve.StartPoint.X > 0.0 && curve.EndPoint.X < 0.0) || (curve.StartPoint.X < 0.0 && curve.EndPoint.X > 0.0)) { var len = curve.Length(); curve.SubCurve(curve.StartPoint, curve.GetPointsByLength(len / 2.0)[1], out curve); } var reg = new Region(curve); if (hasOffset && flat) { reg.Translate(Vector3D.AxisZ * direction * thickness); } else if (hasOffset) { reg = new Region(curve.Offset(direction * thickness, Vector3D.AxisY, 0.0001, true)); } var b = reg.RevolveAsBrep(0.0, 2.0 * Math.PI, Vector3D.AxisZ, Point3D.Origin, 0.0001); if ((flipNorm ^ inner) && !flat) { b.FlipNormal(); } return(b); }
private void RenderText() { List <string> helpStrings = new List <string>(); string formatString = "{0:0.00}"; if (displayHelp) { helpStrings.Add("First person camera behavior"); helpStrings.Add(" Press W and S to move forwards and backwards"); helpStrings.Add(" Press A and D to strafe left and right"); helpStrings.Add(" Press E and Q to move up and down"); helpStrings.Add(" Move mouse to free look"); helpStrings.Add(""); helpStrings.Add("Flight camera behavior"); helpStrings.Add(" Press W and S to move forwards and backwards"); helpStrings.Add(" Press A and D to yaw left and right"); helpStrings.Add(" Press E and Q to move up and down"); helpStrings.Add(" Move mouse to pitch and roll"); helpStrings.Add(""); helpStrings.Add("Press M to enable/disable mouse smoothing"); helpStrings.Add("Press + and - to change camera rotation speed"); helpStrings.Add("Press , and . to change mouse sensitivity"); helpStrings.Add("Press SPACE to toggle between flight and first person behavior"); helpStrings.Add("Press ESC to exit"); helpStrings.Add(""); helpStrings.Add("Press H to hide help"); } else { helpStrings.Add("Camera"); helpStrings.Add(" Speed:" + string.Format(formatString, Viewports[0].Navigation.RotationSpeed)); helpStrings.Add(" Behavior: " + Viewports[0].Navigation.Mode); helpStrings.Add(""); helpStrings.Add("Press H to display help"); } Font myFont = UtilityEx.GetFont(FontFamily, FontStyle, FontWeight, FontSize); int posY = (int)Size.Height - 2 * myFont.Height; for (int i = 0; i < helpStrings.Count; i++) { DrawText(10, posY, helpStrings[i], myFont, Color.White, ContentAlignment.BottomLeft); posY -= (int)1.5 * myFont.Height; } }
protected override bool InsideOrCrossingScreenPolygon(ScreenPolygonParams data) { // Computes the triangles that are inside or crossing the screen polygon for (int i = 0; i < Triangles.Length; i++) { var verts = GetTriangleVertices(Triangles[i]); if (UtilityEx.InsideOrCrossingScreenPolygon(verts[0], verts[1], verts[2], data)) { SelectedSubItems.Add(i); } } return(false); }
protected override bool InsideOrCrossingScreenPolygon(ScreenPolygonParams data) { // Computes the lines that are inside or crossing the screen polygon for (int i = 0; i < Lines.Length; i++) { Segment2D seg; IndexLine line = Lines[i]; Point3D pt1 = Vertices[line.V1]; Point3D pt2 = Vertices[line.V2]; Point3D screenP1 = vp.Camera.WorldToScreen(pt1, data.ViewFrame); Point3D screenP2 = vp.Camera.WorldToScreen(pt2, data.ViewFrame); if (screenP1.Z > 1 || screenP2.Z > 1) { return(false); // for perspective } seg = new Segment2D(screenP1, screenP2); if (UtilityEx.PointInPolygon(screenP1, data.ScreenPolygon) || UtilityEx.PointInPolygon(screenP2, data.ScreenPolygon)) { SelectedSubItems.Add(i); continue; } for (int j = 0; j < data.ScreenSegments.Count; j++) { Point2D i0; if (Segment2D.Intersection(data.ScreenSegments[j], seg, out i0)) { SelectedSubItems.Add(i); break; } } } return(false); }
private bool SetIntersectionCurves(CaseArgs args) { if (!GetIntersectionCurves(args.Shell, args.Neck, out var tmpCurves)) { return(false); } tmpCurves = UtilityEx.GetConnectedCurves(tmpCurves, 0.0001).ToList(); var ordered = tmpCurves.OrderByDescending(c => c.StartPoint.X); _intersectionCurves.Add(ordered.Last()); if (tmpCurves.Count > 1) { _intersectionCurves.Add(ordered.First()); } _intersectOrigin = FindCenter(_innerIntersectionCurve.GetIndividualCurves()); _relOrigin = new Point3D(0, 0, _intersectOrigin.Z); return(true); }
protected override void DrawOverlay(DrawSceneParams myParams) { double Height = Size.Height; double Width = Size.Width; renderContext.SetState(depthStencilStateType.DepthTestOff); renderContext.SetState(blendStateType.Blend); // Draw the transparent ruler renderContext.SetColorWireframe(Color.FromArgb((int)(0.4 * 255), 255, 255, 255)); renderContext.SetState(rasterizerStateType.CCW_PolygonFill_NoCullFace_NoPolygonOffset); // Vertical Ruler renderContext.DrawQuad(new RectangleF(0, 0, rulerSize, (float)(Height - rulerSize))); // Horizontal Ruler renderContext.DrawQuad(new RectangleF(rulerSize, (float)(Height - rulerSize), (float)(Width - rulerSize), rulerSize)); renderContext.SetState(blendStateType.NoBlend); // choose a string format with 2 decimal numbers string formatString = "{0:0.##}"; double worldToScreen = (Height - rulerSize) / (upperRightWorldCoord.Y - lowerLeftWorldCoord.Y); double stepWorldX = 5, stepWorldY = 5; double worldHeight = upperRightWorldCoord.Y - lowerLeftWorldCoord.Y; double nlinesH = (worldHeight / stepWorldY); double worldWidth = upperRightWorldCoord.X - lowerLeftWorldCoord.X; double nlinesW = (worldWidth / stepWorldX); RefineStep(nlinesH, worldHeight, ref stepWorldY); RefineStep(nlinesW, worldWidth, ref stepWorldX); double stepWorld = Math.Min(stepWorldX, stepWorldY); double stepScreen = stepWorld * worldToScreen; /////////////////////////// // Vertical ruler /////////////////////////// // First line Y world coordinate double startYWorld = stepWorld * Math.Floor(lowerLeftWorldCoord.Y / stepWorld); Point2D firstLineScreenPositionY = new Point2D(0, originScreen.Y + startYWorld * worldToScreen); double currentScreenY = firstLineScreenPositionY.Y; double shorterLineXPos = (firstLineScreenPositionY.X + rulerSize) / 2; // draw a longer line each 5 lines. The origin must be a longer line. int countShortLinesY = (int)(Math.Round((currentScreenY - originScreen.Y) / stepScreen)) % 5; // Draw the ruler lines renderContext.SetLineSize(1); double left; Font myFont = UtilityEx.GetFont(FontFamily, FontStyle, FontWeight, FontSize); for (double y = startYWorld; y < upperRightWorldCoord.Y; y += stepWorld, currentScreenY += stepScreen) { if (countShortLinesY % 5 == 0) { left = firstLineScreenPositionY.X; } else { left = shorterLineXPos; }; renderContext.SetColorWireframe(Color.Black); renderContext.DrawLine(new Point2D(left, currentScreenY), new Point2D(rulerSize, currentScreenY)); DrawText((int)firstLineScreenPositionY.X, (int)currentScreenY, string.Format(formatString, y), myFont, Color.Black, ContentAlignment.BottomLeft); countShortLinesY++; } /////////////////////////// // Horizontal ruler /////////////////////////// // First line X world coordinate double startXWorld = stepWorld * Math.Ceiling(lowerLeftWorldCoord.X / stepWorld); Point2D firstLineScreenPositionX = new Point2D(originScreen.X + startXWorld * worldToScreen, 0); double currentScreenX = firstLineScreenPositionX.X; double shorterLineYPos = (firstLineScreenPositionX.Y + rulerSize) / 2; int countShortLinesX = (int)(Math.Round((currentScreenX - originScreen.X) / stepScreen)) % 5; double top; for (double x = startXWorld; x < upperRightWorldCoord.X; x += stepWorld, currentScreenX += stepScreen) { if (countShortLinesX % 5 == 0) { top = firstLineScreenPositionX.Y; } else { top = shorterLineYPos; } renderContext.SetColorWireframe(Color.Black); renderContext.DrawLine(new Point2D(currentScreenX, Height - top), new Point2D(currentScreenX, Height - rulerSize)); DrawText((int)currentScreenX, (int)(Height - rulerSize - firstLineScreenPositionX.Y), string.Format(formatString, x), myFont, Color.Black, ContentAlignment.BottomLeft); countShortLinesX++; } // Draw a red line in correspondence with the mouse position renderContext.SetColorWireframe(Color.Red); if (mousePos.Y > rulerSize) { renderContext.DrawLine(new Point3D(0, Height - mousePos.Y, 0), new Point3D(rulerSize, Height - mousePos.Y, 0)); } if (mousePos.X > rulerSize) { renderContext.DrawLine(new Point3D(mousePos.X, Height, 0), new Point3D(mousePos.X, Height - rulerSize, 0)); } // Draw the logo image at the bottom right corner Bitmap logo = new Bitmap("../../../../../../dataset/Assets/Pictures/Logo.png"); DrawImage(Size.Width - logo.Width - 20, 20, logo); // call the base function base.DrawOverlay(myParams); }
private void CreateTangentEntity() { if (firstSelectedEntity == null) { if (selEntityIndex != -1) { firstSelectedEntity = Entities[selEntityIndex]; selEntityIndex = -1; return; } } else if (secondSelectedEntity == null) { DrawSelectionMark(mouseLocation); renderContext.EnableXOR(false); DrawText(mouseLocation.X, (int)Size.Height - mouseLocation.Y + 10, "Select second circle", new Font("Tahoma", 8.25f), DrawingColor, ContentAlignment.BottomLeft); } if (secondSelectedEntity == null) { if (selEntityIndex != -1) { secondSelectedEntity = Entities[selEntityIndex]; } } if (firstSelectedEntity is ICurve && secondSelectedEntity is ICurve) { if (firstSelectedEntity is Circle && secondSelectedEntity is Circle) { Circle c1 = firstSelectedEntity as Circle; Circle c2 = secondSelectedEntity as Circle; try { if (lineTangents) { Line[] res = UtilityEx.GetLinesTangentToTwoCircles(c1, c2); foreach (Line line in res) { AddAndRefresh(line, ActiveLayerName); } } else if (circleTangents) { List <Circle> res = UtilityEx.GetCirclesTangentToTwoCircles(c1, c2, this.tangentsRadius, this.trimTangent, this.flipTangent); foreach (Circle circ in res) { AddAndRefresh(circ, ActiveLayerName); } } else { return; } } catch { } } ClearAllPreviousCommandData(); } }
protected override void OnContentRendered(EventArgs e) { // defines and add a circle Circle c1 = new Circle(0, 0, 0, 8); // regen with our own tolerance c1.Regen(0.05); // defines and adds a rect LinearPath r1 = new LinearPath(3, 3); r1.Translate(1, -5, 0); // creates an array of points ... Point3D[] points = new Point3D[100]; // ... and fills it for (int y = 0; y < 10; y++) { for (int x = 0; x < 10; x++) { Point3D p = new Point3D(x, y, 0); points[x + y * 10] = p; // adds the point also to the master entity array model1.Entities.Add(new devDept.Eyeshot.Entities.Point(p), System.Drawing.Color.Black); } } // creates an internal constraint Arc a1 = new Arc(0, 0, 0, 5, Utility.DegToRad(120), Utility.DegToRad(220)); a1.Regen(0.05); List <Segment3D> segments = new List <Segment3D>(); for (int i = 0; i < a1.Vertices.Length - 1; i++) { segments.Add(new Segment3D(a1.Vertices[i], a1.Vertices[i + 1])); } // computes triangulation and fill the Mesh entity Mesh m = UtilityEx.Triangulate(c1.Vertices, new Point3D[][] { r1.Vertices }, points, segments); model1.Entities.Add(c1, System.Drawing.Color.Red); model1.Entities.Add(r1, System.Drawing.Color.Blue); model1.Entities.Add(a1, System.Drawing.Color.Green); m.EdgeStyle = Mesh.edgeStyleType.Free; // moves the mesh up m.Translate(0, 0, 5); // adds the mesh to the master entity array model1.Entities.Add(m, System.Drawing.Color.RoyalBlue); // sets the shaded display mode model1.DisplayMode = displayType.Shaded; // fits the model in the viewport model1.ZoomFit(); // sets trimetric view model1.SetView(viewType.Trimetric); // hides origin symbol model1.GetOriginSymbol().Visible = false; //refresh the viewport model1.Invalidate(); base.OnContentRendered(e); }