public VertexSourceAdapter(IVertexSource vertexSource, IGenerator generator) { markers = new null_markers(); this.VertexSource = vertexSource; this.generator = generator; m_status = status.initial; }
public static void Save(IVertexSource vertexSource, string pathAndFileName, bool oldStyle = true) { if (oldStyle) { using (StreamWriter outFile = new StreamWriter(pathAndFileName)) { vertexSource.rewind(0); double x; double y; ShapePath.FlagsAndCommand flagsAndCommand = vertexSource.vertex(out x, out y); do { outFile.WriteLine("{0}, {1}, {2}", x, y, flagsAndCommand.ToString()); flagsAndCommand = vertexSource.vertex(out x, out y); } while (flagsAndCommand != ShapePath.FlagsAndCommand.CommandStop); } } else { using (StreamWriter outFile = new StreamWriter(pathAndFileName)) { foreach (VertexData vertexData in vertexSource.Vertices()) { outFile.WriteLine("{0}, {1}, {2}", vertexData.position.x, vertexData.position.y, vertexData.command.ToString()); } } } }
public static Mesh TriangulateFaces(IVertexSource vertexSource) { vertexSource.rewind(); CachedTesselator teselatedSource = new CachedTesselator(); VertexSourceToTesselator.SendShapeToTesselator(teselatedSource, vertexSource); Mesh extrudedVertexSource = new Mesh(); int numIndicies = teselatedSource.IndicesCache.Count; // build the top first so it will render first when we are translucent for (int i = 0; i < numIndicies; i += 3) { Vector2 v0 = teselatedSource.VerticesCache[teselatedSource.IndicesCache[i + 0].Index].Position; Vector2 v1 = teselatedSource.VerticesCache[teselatedSource.IndicesCache[i + 1].Index].Position; Vector2 v2 = teselatedSource.VerticesCache[teselatedSource.IndicesCache[i + 2].Index].Position; if (v0 == v1 || v1 == v2 || v2 == v0) { continue; } Vertex topVertex0 = extrudedVertexSource.CreateVertex(new Vector3(v0, 0)); Vertex topVertex1 = extrudedVertexSource.CreateVertex(new Vector3(v1, 0)); Vertex topVertex2 = extrudedVertexSource.CreateVertex(new Vector3(v2, 0)); extrudedVertexSource.CreateFace(new Vertex[] { topVertex0, topVertex1, topVertex2 }); } return extrudedVertexSource; }
///<summary> ///</summary> ///<param name="source"></param> ///<param name="generator"></param> public ConverterAdaptorVcgen(IVertexSource source, IGenerator generator) { _markers = new NullMarkers(); _source = source; _generator = generator; _status = EStatus.Initial; }
public ConvAdaptorVcgen(IVertexSource source, IGenerator generator) { this.markers = null; // TODO NullMarkers(); this.source = source; this.generator = generator; this.status = Status.Initial; }
public CurveConverter(IVertexSource source) { m_curve3 = new Curve3(); m_curve4 = new Curve4(); m_source=(source); m_last_x=(0.0); m_last_y=(0.0); }
public FlattenCurves(IVertexSource vertexSource) { m_curve3 = new Curve3(); m_curve4 = new Curve4(); VertexSource = vertexSource; lastX = (0.0); lastY = (0.0); }
private void CheckTestAgainstControl(IVertexSource testVertexSource, string testTypeString) { // there is an assumtion that we got to save valid vertex lists at least once. string controlFileTxt = testTypeString + " Control.Txt"; string vertexSourceFolder = "ControlVertexSources"; PathStorage controlVertexSource = new PathStorage(); if (!Directory.Exists(vertexSourceFolder)) { Directory.CreateDirectory(vertexSourceFolder); } string controlPathAndFileName = Path.Combine(vertexSourceFolder, controlFileTxt); if (File.Exists(controlPathAndFileName)) { VertexSourceIO.Load(controlVertexSource, controlPathAndFileName); // this test the old vertex getting code { string testOldToOldFailPathAndFileName = Path.Combine(vertexSourceFolder, testTypeString + " Test Old Fail.Txt"); bool testOldToOldIsSameAsControl = controlVertexSource.Equals(testVertexSource, oldStyle: true); if (!testOldToOldIsSameAsControl) { // this VertexSource will be in the current output folder inside of VertexSourceFolder VertexSourceIO.Save(testVertexSource, testOldToOldFailPathAndFileName, oldStyle: true); } else if (File.Exists(testOldToOldFailPathAndFileName)) { // we don't want to have these confounding our results. File.Delete(testOldToOldFailPathAndFileName); } Assert.IsTrue(testOldToOldIsSameAsControl); } // this test the new vertex generator code if (true) { string testOldToNewFailPathAndFileName = Path.Combine(vertexSourceFolder, testTypeString + " Test New Fail.Txt"); bool testOldToNewIsSameAsControl = controlVertexSource.Equals(testVertexSource, oldStyle: false); if (!testOldToNewIsSameAsControl) { // this VertexSource will be in the current output folder inside of VertexSourceFolder VertexSourceIO.Save(testVertexSource, testOldToNewFailPathAndFileName, oldStyle: false); } else if (File.Exists(testOldToNewFailPathAndFileName)) { // we don't want to have these confounding our results. File.Delete(testOldToNewFailPathAndFileName); } Assert.IsTrue(testOldToNewIsSameAsControl); } // If you want to create new control VertexSources select SetNextStatement to inside the else condition to creat them. } else { VertexSourceIO.Save(testVertexSource, controlPathAndFileName); } }
public static bool bounding_rect_single(IVertexSource vs, int path_id, ref RectangleDouble rect) { double x1, y1, x2, y2; bool rValue = bounding_rect_single(vs, path_id, out x1, out y1, out x2, out y2); rect.Left = x1; rect.Bottom = y1; rect.Right = x2; rect.Top = y2; return rValue; }
public static bool BoundingRectSingle(IVertexSource vs, uint path_id, ref RectD rect) { double x1, y1, x2, y2; bool rValue = BoundingRectSingle(vs, path_id, out x1, out y1, out x2, out y2); rect.x1 = x1; rect.y1 = y1; rect.x2 = x2; rect.y2 = y2; return rValue; }
public blur() { m_rbuf2 = new ImageBuffer(); m_shape_bounds = new RectangleDouble(); m_method = new RadioButtonGroup(new Vector2(10.0, 10.0), new Vector2(130.0, 60.0)); m_radius = new Slider(new Vector2(130 + 10.0, 10.0 + 4.0), new Vector2(290, 8.0)); m_shadow_ctrl = new PolygonEditWidget(4); m_channel_r = new CheckBox(10.0, 80.0, "Red"); m_channel_g = new CheckBox(10.0, 95.0, "Green"); m_channel_b = new CheckBox(10.0, 110.0, "Blue"); m_FlattenCurves = new CheckBox(10, 315, "Convert And Flatten Curves"); m_FlattenCurves.Checked = true; AddChild(m_method); m_method.AddRadioButton("Stack Blur"); m_method.AddRadioButton("Recursive Blur"); m_method.AddRadioButton("Channels"); m_method.SelectedIndex = 1; AddChild(m_radius); m_radius.SetRange(0.0, 40.0); m_radius.Value = 15.0; m_radius.Text = "Blur Radius={0:F2}"; AddChild(m_shadow_ctrl); AddChild(m_channel_r); AddChild(m_channel_g); AddChild(m_channel_b); AddChild(m_FlattenCurves); m_channel_g.Checked = true; m_sl = new ScanlineCachePacked8(); StyledTypeFace typeFaceForLargeA = new StyledTypeFace(LiberationSansFont.Instance, 300, flatenCurves: false); m_path = typeFaceForLargeA.GetGlyphForCharacter('a'); Affine shape_mtx = Affine.NewIdentity(); shape_mtx *= Affine.NewTranslation(150, 100); m_path = new VertexSourceApplyTransform(m_path, shape_mtx); m_shape = new FlattenCurves(m_path); bounding_rect.bounding_rect_single(m_shape, 0, ref m_shape_bounds); m_shadow_ctrl.SetXN(0, m_shape_bounds.Left); m_shadow_ctrl.SetYN(0, m_shape_bounds.Bottom); m_shadow_ctrl.SetXN(1, m_shape_bounds.Right); m_shadow_ctrl.SetYN(1, m_shape_bounds.Bottom); m_shadow_ctrl.SetXN(2, m_shape_bounds.Right); m_shadow_ctrl.SetYN(2, m_shape_bounds.Top); m_shadow_ctrl.SetXN(3, m_shape_bounds.Left); m_shadow_ctrl.SetYN(3, m_shape_bounds.Top); m_shadow_ctrl.line_color(new RGBA_Floats(0, 0.3, 0.5, 0.3)); }
public override void Render(IVertexSource vertexSource, int pathIndexToRender, RGBA_Bytes colorBytes) { m_Rasterizer.reset(); Affine transform = GetTransform(); if (!transform.IsIdentity()) { vertexSource = new conv_transform(vertexSource, transform); } m_Rasterizer.add_path(vertexSource, pathIndexToRender); Renderer.RenderSolid(m_DestImage, m_Rasterizer, m_ScanlineCache, colorBytes); }
public void RenderSolidAllPaths(IImageByte destImage, IRasterizer ras, IScanlineCache sl, IVertexSource vs, RGBA_Bytes[] color_storage, int[] path_id, int num_paths) { for (int i = 0; i < num_paths; i++) { ras.reset(); ras.add_path(vs, path_id[i]); RenderSolid(destImage, ras, sl, color_storage[i]); } }
public static void SendShapeToTesselator(VertexTesselatorAbstract tesselator, IVertexSource vertexSource) { #if !DEBUG try #endif { tesselator.BeginPolygon(); ShapePath.FlagsAndCommand PathAndFlags = 0; double x, y; bool haveBegunContour = false; while (!ShapePath.is_stop(PathAndFlags = vertexSource.vertex(out x, out y))) { if (ShapePath.is_close(PathAndFlags) || (haveBegunContour && ShapePath.is_move_to(PathAndFlags))) { tesselator.EndContour(); haveBegunContour = false; } if (!ShapePath.is_close(PathAndFlags)) { if (!haveBegunContour) { tesselator.BeginContour(); haveBegunContour = true; } tesselator.AddVertex(x, y); } } if (haveBegunContour) { tesselator.EndContour(); } tesselator.EndPolygon(); } #if !DEBUG catch { } #endif }
private PathStorage CombinePaths(IVertexSource a, IVertexSource b, ClipType clipType) { List<List<IntPoint>> aPolys = VertexSourceToClipperPolygons.CreatePolygons(a); List<List<IntPoint>> bPolys = VertexSourceToClipperPolygons.CreatePolygons(b); Clipper clipper = new Clipper(); clipper.AddPaths(aPolys, PolyType.ptSubject, true); clipper.AddPaths(bPolys, PolyType.ptClip, true); List<List<IntPoint>> intersectedPolys = new List<List<IntPoint>>(); clipper.Execute(clipType, intersectedPolys); PathStorage output = VertexSourceToClipperPolygons.CreatePathStorage(intersectedPolys); output.Add(0, 0, ShapePath.FlagsAndCommand.CommandStop); return output; }
public override void Render(IVertexSource vertexSource, int pathIndexToRender, IColorType colorBytes) { rasterizer.reset(); Affine transform = GetTransform(); if (!transform.is_identity()) { vertexSource = new VertexSourceApplyTransform(vertexSource, transform); } rasterizer.add_path(vertexSource, pathIndexToRender); if (destImageByte != null) { scanlineRenderer.RenderSolid(destImageByte, rasterizer, m_ScanlineCache, colorBytes.GetAsRGBA_Bytes()); DestImage.MarkImageChanged(); } else { scanlineRenderer.RenderSolid(destImageFloat, rasterizer, m_ScanlineCache, colorBytes.GetAsRGBA_Floats()); destImageFloat.MarkImageChanged(); } }
private PathStorage CombinePaths(IVertexSource a, IVertexSource b, ClipType clipType) { List<List<IntPoint>> aPolys = CreatePolygons(a); List<List<IntPoint>> bPolys = CreatePolygons(b); Clipper clipper = new Clipper(); clipper.AddPaths(aPolys, PolyType.ptSubject, true); clipper.AddPaths(bPolys, PolyType.ptClip, true); List<List<IntPoint>> intersectedPolys = new List<List<IntPoint>>(); clipper.Execute(clipType, intersectedPolys); PathStorage output = new PathStorage(); foreach (List<IntPoint> polygon in intersectedPolys) { bool first = true; foreach (IntPoint point in polygon) { if (first) { output.Add(point.X / 1000.0, point.Y / 1000.0, ShapePath.FlagsAndCommand.CommandMoveTo); first = false; } else { output.Add(point.X / 1000.0, point.Y / 1000.0, ShapePath.FlagsAndCommand.CommandLineTo); } } output.ClosePolygon(); } output.Add(0, 0, ShapePath.FlagsAndCommand.CommandStop); return output; }
public static List<List<IntPoint>> CreatePolygons(IVertexSource sourcePath, double scaling = 1000) { List<List<IntPoint>> allPolys = new List<List<IntPoint>>(); List<IntPoint> currentPoly = null; VertexData last = new VertexData(); VertexData first = new VertexData(); bool addedFirst = false; foreach (VertexData vertexData in sourcePath.Vertices()) { if (vertexData.IsLineTo) { if (!addedFirst) { currentPoly.Add(new IntPoint((long)(last.position.x * scaling), (long)(last.position.y * scaling))); addedFirst = true; first = last; } currentPoly.Add(new IntPoint((long)(vertexData.position.x * scaling), (long)(vertexData.position.y * scaling))); last = vertexData; } else { addedFirst = false; currentPoly = new List<IntPoint>(); allPolys.Add(currentPoly); if (vertexData.IsMoveTo) { last = vertexData; } else { last = first; } } } return allPolys; }
public MomsSolitaire() { m_ShuffleButton = new Button("Shuffle", 20, 10); m_ShuffleButton.Click += new Button.ButtonEventHandler(DoShuffle); AddChild(m_ShuffleButton); m_UndoButton = new Button("Undo", 120, 10); m_UndoButton.Click += new Button.ButtonEventHandler(DoUndo); AddChild(m_UndoButton); m_NewGameButton = new Button("New Game", 530, 350); m_NewGameButton.Click += new Button.ButtonEventHandler(DoNewGame); AddChild(m_NewGameButton); String inputString = "M -4,0 L 0,6 L 4,0 L 0,-6 z"; m_DiamondShape = CreatePath(inputString, 0, 0); inputString = "M -0.0036575739,1047.6594 L -0.003242788,1047.6598 C -0.57805752,1047.6682 -1.0418252,1047.8121 -1.5280905,1048.3164 C -2.2710057,1049.0869 -2.3624142,1050.7811 -0.8554188,1051.6756 C -1.9609897,1051.1324 -3.4301937,1051.5612 -3.8418147,1052.8315 C -4.230835,1054.0319 -3.3342833,1055.446 -2.030705,1055.5037 C -0.46271141,1055.5731 -0.25927323,1054.5307 -0.25927323,1054.5307 C -0.30401639,1056.0846 -0.30268325,1056.7329 -1.3991304,1056.9219 C -1.454804,1056.9314 -1.4622286,1056.9868 -1.4506204,1057.0616 L 1.4587769,1057.0616 C 1.4703856,1056.9868 1.4629607,1056.9314 1.4072872,1056.9219 C 0.31084199,1056.7329 0.3121745,1056.0846 0.26743186,1054.5307 C 0.26743186,1054.5307 0.47087012,1055.5731 2.0388616,1055.5037 C 3.3424404,1055.446 4.2389918,1054.0319 3.8499716,1052.8315 C 3.4383507,1051.5612 1.9691468,1051.1324 0.86357723,1051.6756 C 2.3705711,1050.7811 2.2791628,1049.0869 1.5362473,1048.3164 C 1.0499825,1047.8121 0.58621566,1047.6682 0.011400931,1047.6598 C 0.006741066,1047.6587 0.0011981822,1047.6595 -0.0036575739,1047.6594 z"; m_ClubShape = CreatePath(inputString, 0, -1052); inputString = "M -1.8088716,1048.1286 C -1.8891616,1048.1298 -1.9720416,1048.1368 -2.0574115,1048.1501 C -3.6481016,1048.399 -4.7262116,1050.4536 -3.3973316,1052.136 C -1.9660316,1053.9481 -1.2941415,1054.4327 -0.01629155,1056.5983 L 0.01845845,1056.5983 C 1.2963084,1054.4327 1.9681985,1053.9481 3.3994984,1052.136 C 4.7283785,1050.4536 3.6502684,1048.399 2.0595785,1048.1501 C 0.84266845,1047.9598 0.13995845,1049.0762 0.00085845,1049.3225 C -0.12867155,1049.0932 -0.74468155,1048.1124 -1.8088716,1048.1286 z"; m_HeartShape = CreatePath(inputString, 0, -1052); inputString = "M -0.014134084,1046.8659 C -0.11617408,1047.0729 -0.51444404,1048.0169 -1.3283268,1049.1402 C -2.2279798,1050.3819 -2.8141348,1051.01 -3.5427888,1052.198 C -4.0205138,1052.9768 -4.5747888,1055.4361 -2.5444308,1055.9721 C -0.68185405,1056.4637 -0.31250405,1055.0924 -0.31250405,1055.0924 C -0.36461405,1056.9023 -0.36315405,1057.4807 -1.6400568,1057.7007 C -1.7048928,1057.7118 -1.7136608,1057.7763 -1.7001428,1057.8635 L 1.6996155,1057.8635 C 1.7131255,1057.7763 1.7043655,1057.7118 1.6395255,1057.7007 C 0.36262595,1057.4807 0.36408595,1056.9023 0.31197595,1055.0924 C 0.31197595,1055.0924 0.68132594,1056.4637 2.5438955,1055.9721 C 4.5742555,1055.4361 4.0199855,1052.9768 3.5422555,1052.198 C 2.8136055,1051.01 2.2274455,1050.3819 1.3277955,1049.1402 C 0.51391594,1048.0169 0.11564595,1047.0729 0.013605915,1046.8659 L -0.014134084,1046.8659 z"; m_SpadeShape = CreatePath(inputString, 0, -1052); }
//-----------------------------------------------------BoundingRectSingle //template<class VertexSource, class CoordT> public static bool BoundingRectSingle(IVertexSource vs, uint path_id, out double x1, out double y1, out double x2, out double y2) { double x = 0; double y = 0; bool first = true; x1 = (double)(1); y1 = (double)(1); x2 = (double)(0); y2 = (double)(0); vs.Rewind(path_id); uint PathAndFlags; while (!Path.IsStop(PathAndFlags = vs.Vertex(out x, out y))) { if (Path.IsVertex(PathAndFlags)) { if (first) { x1 = (double)(x); y1 = (double)(y); x2 = (double)(x); y2 = (double)(y); first = false; } else { if ((double)(x) < x1) x1 = (double)(x); if ((double)(y) < y1) y1 = (double)(y); if ((double)(x) > x2) x2 = (double)(x); if ((double)(y) > y2) y2 = (double)(y); } } } return x1 <= x2 && y1 <= y2; }
public JoinPaths(IVertexSource a, IVertexSource b) : this(new IVertexSource[] { a, b }) { }
public TransformationConverter(IVertexSource VertexSource, Transform.ITransform InTransform) { m_VertexSource = VertexSource; m_Transform = InTransform; }
public static IVertexSource CombineWith(this IVertexSource source, IVertexSource target) { return(new JoinPaths(source, target)); }
public VertexSourceAdapter(IVertexSource vertexSource, IGenerator generator, IMarkers markers) : this(vertexSource, generator) { this.markers = markers; }
// Concatenate path. The path is added as is. public void concat_path(IVertexSource vs) { concat_path(vs, 0); }
public static IVertexSource Translate(this IVertexSource source, double x, double y) { return(new VertexSourceApplyTransform(source, Affine.NewTranslation(x, y))); }
public void Attach(IVertexSource source) { m_source = source; }
public static Mesh Revolve(IVertexSource source, int angleSteps = 30, double angleStart = 0, double angleEnd = MathHelper.Tau) { angleSteps = Math.Max(angleSteps, 3); angleStart = MathHelper.Range0ToTau(angleStart); angleEnd = MathHelper.Range0ToTau(angleEnd); // convert to clipper polygons and scale so we can ensure good shapes Polygons polygons = source.CreatePolygons(); // ensure good winding and consistent shapes // clip against x=0 left and right // mirror left material across the origin // union mirrored left with right material // convert the data back to PathStorage VertexStorage cleanedPath = polygons.CreateVertexStorage(); Mesh mesh = new Mesh(); var hasStartAndEndFaces = angleStart > 0.000001; hasStartAndEndFaces |= angleEnd < MathHelper.Tau - 0.000001; // check if we need to make closing faces if (hasStartAndEndFaces) { // make a face for the start CachedTesselator teselatedSource = new CachedTesselator(); Mesh extrudedVertexSource = TriangulateFaces(source, teselatedSource); extrudedVertexSource.Transform(Matrix4X4.CreateRotationX(MathHelper.Tau / 4)); extrudedVertexSource.Transform(Matrix4X4.CreateRotationZ(angleStart)); mesh.CopyFaces(extrudedVertexSource); } // make the outside shell double angleDelta = (angleEnd - angleStart) / angleSteps; double currentAngle = angleStart; if (!hasStartAndEndFaces) { angleSteps--; } for (int i = 0; i < angleSteps; i++) { AddRevolveStrip(cleanedPath, mesh, currentAngle, currentAngle + angleDelta); currentAngle += angleDelta; } if (!hasStartAndEndFaces) { if (((angleEnd - angleStart) < .0000001 || (angleEnd - MathHelper.Tau - angleStart) < .0000001) && (angleEnd - currentAngle) > .0000001) { // make sure we close the shape exactly AddRevolveStrip(cleanedPath, mesh, currentAngle, angleStart); } } else // add the end face { // make a face for the end CachedTesselator teselatedSource = new CachedTesselator(); Mesh extrudedVertexSource = TriangulateFaces(source, teselatedSource); extrudedVertexSource.Transform(Matrix4X4.CreateRotationX(MathHelper.Tau / 4)); extrudedVertexSource.Transform(Matrix4X4.CreateRotationZ(currentAngle)); extrudedVertexSource.ReverseFaceEdges(); mesh.CopyFaces(extrudedVertexSource); } // return the completed mesh return(mesh); }
public static Mesh TriangulateFaces(IVertexSource vertexSource) { CachedTesselator teselatedSource = new CachedTesselator(); return(TriangulateFaces(vertexSource, teselatedSource)); }
public static Mesh Extrude(IVertexSource vertexSource, double zHeight) { CachedTesselator teselatedSource = new CachedTesselator(); Mesh extrudedVertexSource = TriangulateFaces(vertexSource, teselatedSource); int numIndicies = teselatedSource.IndicesCache.Count; extrudedVertexSource.Translate(new Vector3(0, 0, zHeight)); // then the outside edge for (int i = 0; i < numIndicies; i += 3) { Vector2 v0 = teselatedSource.VerticesCache[teselatedSource.IndicesCache[i + 0].Index].Position; Vector2 v1 = teselatedSource.VerticesCache[teselatedSource.IndicesCache[i + 1].Index].Position; Vector2 v2 = teselatedSource.VerticesCache[teselatedSource.IndicesCache[i + 2].Index].Position; if (v0 == v1 || v1 == v2 || v2 == v0) { continue; } IVertex bottomVertex0 = extrudedVertexSource.CreateVertex(new Vector3(v0, 0)); IVertex bottomVertex1 = extrudedVertexSource.CreateVertex(new Vector3(v1, 0)); IVertex bottomVertex2 = extrudedVertexSource.CreateVertex(new Vector3(v2, 0)); IVertex topVertex0 = extrudedVertexSource.CreateVertex(new Vector3(v0, zHeight)); IVertex topVertex1 = extrudedVertexSource.CreateVertex(new Vector3(v1, zHeight)); IVertex topVertex2 = extrudedVertexSource.CreateVertex(new Vector3(v2, zHeight)); if (teselatedSource.IndicesCache[i + 0].IsEdge) { extrudedVertexSource.CreateFace(new IVertex[] { bottomVertex0, bottomVertex1, topVertex1, topVertex0 }); } if (teselatedSource.IndicesCache[i + 1].IsEdge) { extrudedVertexSource.CreateFace(new IVertex[] { bottomVertex1, bottomVertex2, topVertex2, topVertex1 }); } if (teselatedSource.IndicesCache[i + 2].IsEdge) { extrudedVertexSource.CreateFace(new IVertex[] { bottomVertex2, bottomVertex0, topVertex0, topVertex2 }); } } // then the bottom for (int i = 0; i < numIndicies; i += 3) { Vector2 v0 = teselatedSource.VerticesCache[teselatedSource.IndicesCache[i + 0].Index].Position; Vector2 v1 = teselatedSource.VerticesCache[teselatedSource.IndicesCache[i + 1].Index].Position; Vector2 v2 = teselatedSource.VerticesCache[teselatedSource.IndicesCache[i + 2].Index].Position; if (v0 == v1 || v1 == v2 || v2 == v0) { continue; } IVertex bottomVertex0 = extrudedVertexSource.CreateVertex(new Vector3(v0, 0)); IVertex bottomVertex1 = extrudedVertexSource.CreateVertex(new Vector3(v1, 0)); IVertex bottomVertex2 = extrudedVertexSource.CreateVertex(new Vector3(v2, 0)); extrudedVertexSource.CreateFace(new IVertex[] { bottomVertex2, bottomVertex1, bottomVertex0 }); } return(extrudedVertexSource); }
public static void SendShapeToTesselator(VertexTesselatorAbstract tesselator, IVertexSource vertexSource) { #if !DEBUG try #endif { tesselator.BeginPolygon(); bool haveBegunContour = false; foreach (var vertexData in vertexSource.Vertices()) { if (vertexData.IsStop) { break; } if (haveBegunContour && (vertexData.IsClose || vertexData.IsMoveTo)) { tesselator.EndContour(); haveBegunContour = false; } if (!vertexData.IsClose) { if (!haveBegunContour) { tesselator.BeginContour(); haveBegunContour = true; } tesselator.AddVertex(vertexData.position.X, vertexData.position.Y); } } if (haveBegunContour) { tesselator.EndContour(); } tesselator.EndPolygon(); } #if !DEBUG catch { } #endif }
override public Task Rebuild() { using (RebuildLock()) { using (new CenterAndHeightMantainer(this)) { this.Children.Modify(list => { list.Clear(); }); var brailleText = TextToEncode; if (UseGrade2) { brailleText = BrailleGrade2.ConvertString(brailleText); } double pointSize = 18.5; double pointsToMm = 0.352778; IObject3D textObject = new Object3D(); var offest = 0.0; TypeFacePrinter textPrinter; if (RenderAsBraille) { textPrinter = new TypeFacePrinter(brailleText, new StyledTypeFace(typeFace, pointSize)); } else { textPrinter = new TypeFacePrinter(brailleText, new StyledTypeFace(ApplicationController.GetTypeFace(NamedTypeFace.Liberation_Mono), pointSize)); } foreach (var letter in brailleText.ToCharArray()) { IObject3D letterObject; TypeFacePrinter letterPrinter; if (RenderAsBraille) { letterPrinter = new TypeFacePrinter(letter.ToString(), new StyledTypeFace(typeFace, pointSize)); var scalledLetterPrinter = new VertexSourceApplyTransform(letterPrinter, Affine.NewScaling(pointsToMm)); // add all the spheres to letterObject letterObject = new Object3D(); var vertexCount = 0; var positionSum = Vector2.Zero; var lastPosition = Vector2.Zero; // find each dot outline and get it's center and place a sphere there foreach (var vertex in scalledLetterPrinter.Vertices()) { switch (vertex.command) { case Agg.ShapePath.FlagsAndCommand.Stop: case Agg.ShapePath.FlagsAndCommand.EndPoly: case Agg.ShapePath.FlagsAndCommand.FlagClose: case Agg.ShapePath.FlagsAndCommand.MoveTo: if (vertexCount > 0) { var center = positionSum / vertexCount; double radius = 1.44 / 2; // (center - lastPosition).Length; var sphere = new HalfSphereObject3D(radius * 2, 15) { Color = Color.LightBlue }; sphere.Translate(center.X, center.Y); letterObject.Children.Add(sphere); } vertexCount = 0; positionSum = Vector2.Zero; break; case Agg.ShapePath.FlagsAndCommand.Curve3: case Agg.ShapePath.FlagsAndCommand.Curve4: case Agg.ShapePath.FlagsAndCommand.LineTo: vertexCount++; lastPosition = vertex.position; positionSum += lastPosition; break; } } } else { letterPrinter = new TypeFacePrinter(letter.ToString(), new StyledTypeFace(ApplicationController.GetTypeFace(NamedTypeFace.Liberation_Mono), pointSize)); var scalledLetterPrinter = new VertexSourceApplyTransform(letterPrinter, Affine.NewScaling(pointsToMm)); letterObject = new Object3D() { Mesh = VertexSourceToMesh.Extrude(scalledLetterPrinter, 1), Color = Color.LightBlue }; } letterObject.Matrix = Matrix4X4.CreateTranslation(offest, 0, 0); textObject.Children.Add(letterObject); offest += letterPrinter.GetSize(letter.ToString()).X *pointsToMm; } // add a plate under the dots var padding = .9 * pointSize * pointsToMm / 2; var size = textPrinter.LocalBounds * pointsToMm; // make the base var basePath = new VertexStorage(); basePath.MoveTo(0, 0); basePath.LineTo(size.Width + padding, 0); basePath.LineTo(size.Width + padding, size.Height + padding); basePath.LineTo(padding, size.Height + padding); basePath.LineTo(0, size.Height); IObject3D basePlate = new Object3D() { Mesh = VertexSourceToMesh.Extrude(basePath, BaseHeight) }; basePlate = new AlignObject3D(basePlate, FaceAlign.Top, textObject, FaceAlign.Bottom, 0, 0, .01); basePlate = new AlignObject3D(basePlate, FaceAlign.Left | FaceAlign.Front, size.Left - padding / 2, size.Bottom - padding / 2); this.Children.Add(basePlate); basePlate.Matrix *= Matrix4X4.CreateRotationX(MathHelper.Tau / 4); // add an optional chain hook if (AddHook) { // x 10 to make it smoother double edgeWidth = 3; double height = basePlate.ZSize(); IVertexSource leftSideObject = new RoundedRect(0, 0, height / 2, height, 0) { ResolutionScale = 10 }; IVertexSource cicleObject = new Ellipse(0, 0, height / 2, height / 2) { ResolutionScale = 10 }; cicleObject = new Align2D(cicleObject, Side2D.Left | Side2D.Bottom, leftSideObject, Side2D.Left | Side2D.Bottom, -.01); IVertexSource holeObject = new Ellipse(0, 0, height / 2 - edgeWidth, height / 2 - edgeWidth) { ResolutionScale = 10 }; holeObject = new SetCenter2D(holeObject, cicleObject.GetBounds().Center); IVertexSource hookPath = leftSideObject.Plus(cicleObject); hookPath = hookPath.Minus(holeObject); IObject3D chainHook = new Object3D() { Mesh = VertexSourceToMesh.Extrude(hookPath, BaseHeight), Matrix = Matrix4X4.CreateRotationX(MathHelper.Tau / 4) }; chainHook = new AlignObject3D(chainHook, FaceAlign.Left | FaceAlign.Bottom | FaceAlign.Back, basePlate, FaceAlign.Right | FaceAlign.Bottom | FaceAlign.Back, -.01); this.Children.Add(chainHook); } // add the object that is the dots this.Children.Add(textObject); textObject.Matrix *= Matrix4X4.CreateRotationX(MathHelper.Tau / 4); } } Parent?.Invalidate(new InvalidateArgs(this, InvalidateType.Children)); return(Task.CompletedTask); }
public LinearExtrude(IVertexSource vertexSource) { }
private void Subtract(CancellationToken cancellationToken, IProgress <ProgressStatus> reporter) { SourceContainer.Visible = true; RemoveAllButSource(); var parentOfSubtractTargets = SourceContainer.DescendantsAndSelfMultipleChildrenFirstOrSelf(); if (parentOfSubtractTargets.Children.Count() < 2) { if (parentOfSubtractTargets.Children.Count() == 1) { this.Children.Add(SourceContainer.Clone()); SourceContainer.Visible = false; } return; } CleanUpSelectedChildrenNames(this); var removeVisibleItems = parentOfSubtractTargets.Children .Where((i) => SelectedChildren .Contains(i.ID)) .SelectMany(c => c.VisiblePaths()) .ToList(); var keepItems = parentOfSubtractTargets.Children .Where((i) => !SelectedChildren .Contains(i.ID)); var keepVisibleItems = keepItems.SelectMany(c => c.VisiblePaths()).ToList(); if (removeVisibleItems.Any() && keepVisibleItems.Any()) { var totalOperations = removeVisibleItems.Count * keepVisibleItems.Count; double amountPerOperation = 1.0 / totalOperations; double percentCompleted = 0; var progressStatus = new ProgressStatus { Status = "Do Subtract" }; bool first = true; foreach (var keep in keepVisibleItems) { var resultsVertexSource = (keep as IPathObject).VertexSource.Transform(keep.Matrix); foreach (var remove in removeVisibleItems) { resultsVertexSource = resultsVertexSource.MergePaths(((IPathObject)remove).VertexSource.Transform(remove.Matrix), ClipperLib.ClipType.ctDifference); // report our progress percentCompleted += amountPerOperation; progressStatus.Progress0To1 = percentCompleted; reporter?.Report(progressStatus); } if (first) { this.VertexSource = resultsVertexSource; first = false; } else { this.VertexSource.MergePaths(resultsVertexSource, ClipperLib.ClipType.ctUnion); } } // this.VertexSource = this.VertexSource.Transform(Matrix.Inverted); first = true; foreach (var child in Children) { if (first) { // hide the source item child.Visible = false; first = false; } else { child.Visible = true; } } } }
/// <summary> /// /// </summary> /// <param name="vertexSource"></param> /// <param name="idx"></param> /// <param name="color"></param> public void Render(IVertexSource vertexSource, uint idx, RGBA_Bytes color) { m_Rasterizer.Reset(); Affine transform = Transform; if (!transform.IsIdentity()) { vertexSource = new TransformationConverter(vertexSource, transform); } m_Rasterizer.AddPath(vertexSource, idx); Renderer.RenderSolid(m_PixelFormat, m_Rasterizer, m_Scanline, color); }
public static void SendShapeToTesselator(VertexTesselatorAbstract tesselator, IVertexSource vertexSource) { SendShapeToTesselator(tesselator, vertexSource.Vertices()); }
void Attach(IVertexSource vertexSource) { this.VertexSource = vertexSource; }
public static void SendShapeToTesselator(VertexTesselatorAbstract tesselator, IVertexSource vertexSource) { #if !DEBUG try #endif { tesselator.BeginPolygon(); ShapePath.FlagsAndCommand PathAndFlags = 0; double x, y; bool haveBegunContour = false; while (!ShapePath.is_stop(PathAndFlags = vertexSource.vertex(out x, out y))) { if (ShapePath.is_close(PathAndFlags) || (haveBegunContour && ShapePath.is_move_to(PathAndFlags))) { tesselator.EndContour(); haveBegunContour = false; } if (!ShapePath.is_close(PathAndFlags)) { if (!haveBegunContour) { tesselator.BeginContour(); haveBegunContour = true; } tesselator.AddVertex(x, y); } } if (haveBegunContour) { tesselator.EndContour(); } tesselator.EndPolygon(); } #if !DEBUG catch { } #endif }
public CombinePaths(IVertexSource a, IVertexSource b) : this(new IVertexSource[] { a, b }) { }
public void add_path(IVertexSource vs) { add_path(vs, 0); }
public abstract void Render(IVertexSource vertexSource, int pathIndexToRender, IColorType colorType);
public void Render(IVertexSource vertexSource, double x, double y, IColorType color) { Render(new VertexSourceApplyTransform(vertexSource, Affine.NewTranslation(x, y)), 0, color); }
void Attach(IVertexSource vertexSource) { this.VertexSource = vertexSource; }
public static IVertexSource Scale(this IVertexSource source, double scale) { return(new VertexSourceApplyTransform(source, Affine.NewScaling(scale))); }
public void Render(IVertexSource vertexSource, IColorType color) { Render(vertexSource, 0, color); }
public static IVertexSource Minus(this IVertexSource a, IVertexSource b) { return(CombinePaths(a, b, ClipType.ctDifference)); }
public void Render(IVertexSource vertexSource, Vector2 position, IColorType color) { Render(new VertexSourceApplyTransform(vertexSource, Affine.NewTranslation(position.X, position.Y)), 0, color); }
public static IVertexSource Plus(this IVertexSource a, IVertexSource b) { return(CombinePaths(a, b, ClipType.ctUnion)); }
public void Attach(IVertexSource VertexSource) { m_VertexSource = VertexSource; }
public GlyphWithUnderline(IVertexSource glyph, int advanceForCharacter, int Underline_position, int Underline_thickness) { underline = new RoundedRect(new RectangleDouble(0, Underline_position, advanceForCharacter, Underline_position + Underline_thickness), 0); this.glyph = glyph; }
public static IVertexSource Union(this IVertexSource a, IVertexSource b) { return(a.Plus(b)); }
public void AddPath(IVertexSource vs, uint path_id) { double x = 0; double y = 0; uint PathAndFlags; vs.Rewind(path_id); if (m_outline.IsSorted) { Reset(); } while (!Path.IsStop(PathAndFlags = vs.Vertex(out x, out y))) { AddVertex(x, y, PathAndFlags); } //DebugFile.Print("Test"); }
//========================================================render_all_paths public static void RenderSolidAllPaths(IPixelFormat pixFormat, IRasterizer ras, IScanline sl, IVertexSource vs, RGBA_Bytes[] color_storage, uint[] path_id, uint num_paths) { for(uint i = 0; i < num_paths; i++) { ras.Reset(); #if use_timers AddPathTimer.Start(); #endif ras.AddPath(vs, path_id[i]); #if use_timers AddPathTimer.Stop(); #endif #if use_timers RenderSLTimer.Start(); #endif RenderSolid(pixFormat, ras, sl, color_storage[i]); #if use_timers RenderSLTimer.Stop(); #endif } }
public static IVertexSource Translate(this IVertexSource a, Vector2 delta) { return(new VertexSourceApplyTransform(a, Affine.NewTranslation(delta))); }
/// <summary> /// /// </summary> /// <param name="vertexSource"></param> /// <param name="color"></param> public void Render(IVertexSource vertexSource, RGBA_Bytes color) { Render(vertexSource, 0, color); }
private void CreateAndRenderCombined(Graphics2D graphics2D, IVertexSource ps1, IVertexSource ps2) { PathStorage combined = null; switch (m_operation.SelectedIndex) { case 1: combined = CombinePaths(ps1, ps2, ClipType.ctUnion); break; case 2: combined = CombinePaths(ps1, ps2, ClipType.ctIntersection); break; case 3: combined = CombinePaths(ps1, ps2, ClipType.ctXor); break; case 4: combined = CombinePaths(ps1, ps2, ClipType.ctDifference); break; case 5: combined = CombinePaths(ps2, ps1, ClipType.ctDifference); break; } if (combined != null) { graphics2D.Render(combined, new RGBA_Floats(0.5, 0.0, 0, 0.5).GetAsRGBA_Bytes()); } }
public VertexSourceAdapter(IVertexSource vertexSource, IGenerator generator, IMarkers markers) : this(vertexSource, generator) { this.markers = markers; }
private conv_poly_counter(IVertexSource src) { m_contours = 0; m_points = 0; foreach (VertexData vertexData in src.Vertices()) { if (ShapePath.is_vertex(vertexData.command)) { ++m_points; } if (ShapePath.is_move_to(vertexData.command)) { ++m_contours; } } }
public Contour(IVertexSource vertexSource) : base(vertexSource, new ContourGenerator()) { }
public static IVertexSource Translate(this IVertexSource source, Vector2 vector2) { return(source.Translate(vector2.X, vector2.Y)); }