private static void DrawPath(this WavefrontFormat wf, GraphicsPath path) { byte[] types = path.PathData.Types; PointF[] points = path.PathData.Points; FillMode fillMode = path.FillMode; List <Vec2d> _points = new List <Vec2d>(); for (int i = 0; i < types.Length; i++) { PathPointType tipo = (PathPointType)types[i] & PathPointType.PathTypeMask; switch (tipo) { case PathPointType.Start: { _points.Add(new Vec2d(points[i].X, points[i].Y)); break; } case PathPointType.Line: { _points.Add(new Vec2d(points[i].X, points[i].Y)); break; } case PathPointType.Bezier3: { // NOTA: se pintará una bezier en breve. _points.Add(new Vec2d(points[i].X, points[i].Y)); i++; _points.Add(new Vec2d(points[i].X, points[i].Y)); i++; _points.Add(new Vec2d(points[i].X, points[i].Y)); break; } default: { throw new IndexOutOfRangeException(); } } // El ultimo tipo determina si hay que cerrar. bool cerrar = ((PathPointType)types[i] & PathPointType.CloseSubpath) == PathPointType.CloseSubpath; if (cerrar) { if (_points.Count > 0) { wf.AddLines(_points, true); _points.Clear(); } } } if (_points.Count > 0) { wf.AddLines(_points, false); _points.Clear(); } }
public static void DrawString(this WavefrontFormat wf, string color, Vec2d pt, FontFamily family, FontStyle style, float sizeInPoints, string text) { float dpiY = 1; float emSize = dpiY * sizeInPoints / 72; using (GraphicsPath path = new GraphicsPath()) { //float dpiY = 1; path.AddString(text, family, (int)style, emSize, new PointF(0, 0), StringFormat.GenericTypographic); float pathheight = path.GetBounds().Height; path.Transform(new Matrix(1, 0, 0, -1, 0, pathheight)); path.Transform(new Matrix(1, 0, 0, 1, (float)pt.X, (float)pt.Y)); path.Flatten(new Matrix(), 0.01f); DrawPath(wf, path); } }
public static WavefrontFormat DrawClothoRadius(this WavefrontFormat wf, bool invertY, double a, string radiusColor) { List <int> indices = new List <int>(); double lmax = ClothoUtils.GetMaxL(a); int c = 100; for (int i = -c; i <= c; i++) { double s = i * lmax / c; double r = ClothoUtils.ClothoRadious(s, invertY, a); if (double.IsInfinity(r)) { r = SysMath.Sign(r) * 1000; } int v0 = wf.AddVertex(new Vec2d(s, r)); indices.Add(v0); //double dx, dy; //MathUtils.DClotho(s, r, a, out dx, out dy); } wf.UseMaterial(radiusColor); wf.AddLines(indices, false); return(wf); }
public static WavefrontFormat DrawCurve(this WavefrontFormat wf, string color, ICurve2 curve, int count = 100) { wf.UseMaterial(color); if (curve is ComposedCurve2) { int i = 0; ComposedCurve2 composed = (ComposedCurve2)curve; foreach (ICurve2 segment in composed.GetSegments()) { /*Vec2d pt = segment.GetPosition(segment.TMin); * wf.DrawFigure(color, WaveFigure.X, pt, 1); * wf.DrawString(color, pt, FontFamily.GenericSerif, FontStyle.Regular, 1000, "" + (i++));*/ //if (segment is CircleArc2) { wf.AddLines(MathUtils.For(segment.TMin, segment.TMax, count).Select(segment.GetPosition), false); } } /*if (!curve.IsClosed) * { * Vec2d pt = curve.GetPosition(curve.TMax); * wf.DrawFigure(color, WaveFigure.X, pt, 1); * wf.DrawString(color, pt, FontFamily.GenericSerif, FontStyle.Regular, 1000, "" + (i++)); * }*/ } else { wf.AddLines(MathUtils.For(curve.TMin, curve.TMax, count).Select(curve.GetPosition), false); } return(wf); }
public static WavefrontFormat DrawClotho(this WavefrontFormat wf, bool invertY, double a, string clothoColor) { List <int> indices = new List <int>(); int c = 100; for (int i = -c; i <= c; i++) { double lmax = ClothoUtils.GetMaxL(a); double s = i * lmax / c; double x, y; ClothoUtils.Clotho(s, invertY, a, out x, out y); int v0 = wf.AddVertex(new Vec2d(x, y)); indices.Add(v0); //double dx, dy; //MathUtils.DClotho(s, r, a, out dx, out dy); } wf.UseMaterial(clothoColor); wf.AddLines(indices, false); return(wf); }
public static void DrawString(this WavefrontFormat wf, string color, Vec2d pt, Font font, string text) { DrawString(wf, color, pt, font.FontFamily, font.Style, font.SizeInPoints, text); }
public static WavefrontFormat DrawClotho(this WavefrontFormat wf, string color, ClothoidArc2 arc) { wf.UseMaterial(color); wf.AddLines(MathUtils.For(arc.TMin, arc.TMax, 10).Select(arc.GetPosition), false); return(wf); }
public static WavefrontFormat DrawPolyline(this WavefrontFormat wf, string color, IEnumerable <Vec2d> points, bool close) { wf.UseMaterial(color); wf.AddLines(points, close); return(wf); }
public static WavefrontFormat DrawLine(this WavefrontFormat wf, string color, Vec2d point, Vec2d v, double ext = 1000) { wf.UseMaterial(color); Vec2d p0 = point.Sub(v.Mul(ext)); Vec2d p1 = point.Add(v.Mul(ext)); wf.AddLines(new Vec2d[] { p0, p1 }, false); return(wf); }
public void Test2() { using (MaterialFormat mf = new MaterialFormat(@"C:\Temp\Default.mtl")) { mf.DefaultColors(); } using (WavefrontFormat wf = new WavefrontFormat(@"C:\Temp\Radio+.obj")) { wf.LoadMaterialLib("Default.mtl"); wf.DrawClotho(false, 10, "Red", "Yellow", "Green", "Magenta"); } using (WavefrontFormat wf = new WavefrontFormat(@"C:\Temp\Radio-.obj")) { wf.LoadMaterialLib("Default.mtl"); wf.DrawClotho(true, 10, "Blue", "Yellow", "Green", "Magenta"); } }
public void Test2() { double a = 10; bool invertY = true; double maxL = ClothoUtils.GetMaxL(a); int ysign = invertY ? -1 : 1; double[] angles = { ysign * 0, ysign *SysMath.PI / 4, ysign *SysMath.PI / 2, ysign * 3 *SysMath.PI / 4 }; using (MaterialFormat mf = new MaterialFormat(@"C:\Temp\Default.mtl")) { mf.DefaultColors(); } using (WavefrontFormat wf = new WavefrontFormat(@"C:\Temp\ClothoidArc2dTest_Test2.obj")) { wf.LoadMaterialLib("Default.mtl"); wf.DrawClotho(invertY, a, "Red"); foreach (double angle in angles) { Vec2d v = vecMath.NewRotate(angle); double l = ClothoUtils.FindTangent(invertY, a, v); wf.DrawLine("Green", ClothoUtils.Clotho(l, invertY, a), v); wf.DrawLine("Magenta", ClothoUtils.Clotho(-l, invertY, a), v); } //wf.DrawLine("Yellow", new Vec2d(0, 0), new Vec2d(1, 0), 100); //wf.DrawLine("Yellow", new Vec2d(0, 0), new Vec2d(0, 1), 100); } }
/// <summary> /// Prueba el constructor ClothoidArc2d(double,Vec2d,Vec2d,double,double). /// </summary> private static void TestClotho(double a, bool invertY, bool negX, double tg0, double tg1, Vec2d p0, Vec2d dir, string fileName = null, bool toWavefront = false) { //double a = 5; //bool invertY = true; //double tg0 = -4 * SysMath.PI / 10; //double tg1 = -SysMath.PI / 10; // Si se indica negX, se invierten las tangentes. int sign = 1; if (negX) { sign = -1; } double l0 = sign * ClothoUtils.FindTangent(invertY, a, tg0); double l1 = sign * ClothoUtils.FindTangent(invertY, a, tg1); double r0 = ClothoUtils.ClothoRadious(l0, invertY, a); double r1 = ClothoUtils.ClothoRadious(l1, invertY, a); Vec2d pp0 = ClothoUtils.Clotho(l0, invertY, a); Vec2d pp1 = ClothoUtils.Clotho(l1, invertY, a); //Vec2d p0 = new Vec2d(5, 5); Vec2d p1 = p0.Add(dir.Mul(pp1.Sub(pp0).Length)); ClothoidArc2 arc = new ClothoidArc2(l0, p0, p1, r0, r1); Assert.IsTrue(arc.Point0.EpsilonEquals(p0, ERROR)); Assert.IsTrue(arc.Point1.EpsilonEquals(p1, ERROR)); Assert.IsTrue(arc.GetRadius(arc.TMin).EpsilonEquals(r0, ERROR)); Assert.IsTrue(arc.GetRadius(arc.TMax).EpsilonEquals(r1, ERROR)); // <- Assert.IsTrue(arc.InvertY == invertY); Assert.IsTrue(arc.A.EpsilonEquals(a, ERROR)); // Salida por fichero de la prueba. if ((fileName != null) && toWavefront) { double figSize = 0.5; string mtl = Path.ChangeExtension(fileName, "mtl"); using (MaterialFormat mf = new MaterialFormat(mtl)) { mf.DefaultColors(); } using (WavefrontFormat wf = new WavefrontFormat(fileName)) { wf.LoadMaterialLib(Path.GetFileName(mtl)); wf.DrawLine("Yellow", Vec2d.Zero, new Vec2d(1, 0), 50); wf.DrawLine("Yellow", Vec2d.Zero, new Vec2d(0, 1), 50); wf.DrawFigure("Blue", WaveFigure.X, ClothoUtils.Clotho(l0, invertY, a), figSize); wf.DrawFigure("Olive", WaveFigure.X, ClothoUtils.Clotho(l1, invertY, a), figSize); wf.DrawClotho(invertY, a, "Red"); wf.DrawClotho("Magenta", arc); wf.DrawFigure("Blue", WaveFigure.X, p0, figSize); wf.DrawFigure("Olive", WaveFigure.X, p1, figSize); } } }
public static WavefrontFormat DrawClotho(this WavefrontFormat wf, bool invertY, double a, string clothoColor, string dirColor, string normalColor, string radColor) { List <int> indices = new List <int>(); List <Tuple <int, int> > normals = new List <Tuple <int, int> >(); List <Tuple <int, int> > dirs = new List <Tuple <int, int> >(); List <Tuple <int, int> > radius = new List <Tuple <int, int> >(); int c = 100; for (int i = -c; i <= c; i++) { double lmax = ClothoUtils.GetMaxL(a); double s = i * lmax / c; double x, y; ClothoUtils.Clotho(s, invertY, a, out x, out y); int v0 = wf.AddVertex(new Vec2d(x, y)); indices.Add(v0); Vec2d n = ClothoUtils.ClothoLeftNormal(s, invertY, a).Norm(); int v1 = wf.AddVertex(new Vec2d(x + n.X, y + n.Y)); normals.Add(Tuple.Create(v0, v1)); double dir = ClothoUtils.ClothoTangent(s, invertY, a); double dx = SysMath.Cos(dir); double dy = SysMath.Sin(dir); Vec2d d = new Vec2d(dx, dy).Norm(); int v2 = wf.AddVertex(new Vec2d(x + 5 * d.X, y + 5 * d.Y)); dirs.Add(Tuple.Create(v0, v2)); double r = ClothoUtils.ClothoRadious(s, invertY, a); if (double.IsInfinity(r)) { r = SysMath.Sign(r) * 100; } int v3 = wf.AddVertex(new Vec2d(x + r * n.X, y + r * n.Y)); radius.Add(Tuple.Create(v0, v3)); //double dx, dy; //MathUtils.DClotho(s, r, a, out dx, out dy); } wf.UseMaterial(clothoColor); wf.AddLines(indices, false); wf.UseMaterial(normalColor); foreach (Tuple <int, int> normal in normals) { wf.AddLines(new[] { normal.Item1, normal.Item2 }, false); } wf.UseMaterial(dirColor); foreach (Tuple <int, int> dir in dirs) { wf.AddLines(new[] { dir.Item1, dir.Item2 }, false); } wf.UseMaterial(radColor); foreach (Tuple <int, int> rr in radius) { wf.AddLines(new[] { rr.Item1, rr.Item2 }, false); } return(wf); }
public static WavefrontFormat DrawFigure(this WavefrontFormat wf, string color, WaveFigure figure, Vec2d point, double size) { wf.UseMaterial(color); switch (figure) { case WaveFigure.Circle: { wf.AddLines(MathUtils.For(0, 2 * SysMath.PI, 20).Select(t => point.Add(vecMath.NewRotate(t).Mul(size))), true); break; } case WaveFigure.Rectangle: { wf.AddLines(new Vec2d[] { point.Add(new Vec2d(size, size)), point.Add(new Vec2d(-size, size)), point.Add(new Vec2d(-size, -size)), point.Add(new Vec2d(size, -size)), }, true); break; } case WaveFigure.Diamond: { wf.AddLines(new Vec2d[] { point.Add(new Vec2d(0, size)), point.Add(new Vec2d(-size, 0)), point.Add(new Vec2d(0, -size)), point.Add(new Vec2d(size, 0)), }, true); break; } case WaveFigure.Plus: { wf.AddLines(new Vec2d[] { point.Add(new Vec2d(0, size)), point.Add(new Vec2d(0, -size)), }, false); wf.AddLines(new Vec2d[] { point.Add(new Vec2d(size, 0)), point.Add(new Vec2d(-size, 0)), }, false); break; } case WaveFigure.X: { wf.AddLines(new Vec2d[] { point.Add(new Vec2d(size, size)), point.Add(new Vec2d(-size, -size)), }, false); wf.AddLines(new Vec2d[] { point.Add(new Vec2d(-size, size)), point.Add(new Vec2d(size, -size)), }, false); break; } default: { throw new Exception(); } } return(wf); }