Example #1
0
        static void FindActualPointCount(PixelFarm.Drawing.VertexStore vxs, out int actualPointCount)
        {
            int    pp = vxs.Count;
            double vtx0, vty0;

            PixelFarm.Drawing.VertexCmd cmd = vxs.GetVertex(--pp, out vtx0, out vty0);
            while (cmd == PixelFarm.Drawing.VertexCmd.NoMore || cmd == PixelFarm.Drawing.VertexCmd.Close)
            {
                cmd = vxs.GetVertex(--pp, out vtx0, out vty0);
            }
            actualPointCount = pp + 1;
        }
Example #2
0
        public void ShowOrgBorderInfo(PixelFarm.Drawing.VertexStore vxs)
        {
            if (!_clearInfoView)
            {
                return;
            }
            _orgCmds.Nodes.Clear();
            _treeView.SuspendLayout();
            _orgVxs = vxs;

            int       count = vxs.Count;
            VertexCmd cmd;
            double    x, y;
            int       index = 0;

            while ((cmd = vxs.GetVertex(index, out x, out y)) != VertexCmd.NoMore)
            {
                var node = new TreeNode()
                {
                    Tag = new NodeInfo(NodeInfoKind.OrgVertexCommand, index)
                };
                node.Text = (index) + " " + cmd + ": (" + x + "," + y + ")";
                _orgCmds.Nodes.Add(node);
                index++;
            }
            _treeView.ResumeLayout();
        }
        public void ShowFlatternBorderInfo(PixelFarm.Drawing.VertexStore vxs)
        {
            if (!_clearInfoView)
            {
                return;
            }
            _flattenVxsNode.Nodes.Clear();
            _treeView.SuspendLayout();
            _flattenVxs = vxs;

            PixelFarm.Drawing.VertexCmd cmd;
            int index = 0;

            while ((cmd = vxs.GetVertex(index, out double x, out double y)) != PixelFarm.Drawing.VertexCmd.NoMore)
            {
                var node = new TreeNode()
                {
                    Tag = new NodeInfo(NodeInfoKind.FlattenVertexCommand, index)
                };
                node.Text = (index) + " " + cmd + ": (" + x + "," + y + ")";
                _flattenVxsNode.Nodes.Add(node);
                index++;
            }
            _treeView.ResumeLayout();
        }
        //======= Crossings Multiply algorithm of InsideTest ========================
        //
        // By Eric Haines, 3D/Eye Inc, [email protected]
        //
        // This version is usually somewhat faster than the original published in
        // Graphics Gems IV; by turning the division for testing the X axis crossing
        // into a tricky multiplication test this part of the test became faster,
        // which had the additional effect of making the test for "both to left or
        // both to right" a bit slower for triangles than simply computing the
        // intersection each time.  The main increase is in triangle testing speed,
        // which was about 15% faster; all other polygon complexities were pretty much
        // the same as before.  On machines where division is very expensive (not the
        // case on the HP 9000 series on which I tested) this test should be much
        // faster overall than the old code.  Your mileage may (in fact, will) vary,
        // depending on the machine and the test data, but in general I believe this
        // code is both shorter and faster.  This test was inspired by unpublished
        // Graphics Gems submitted by Joseph Samosky and Mark Haigh-Hutchinson.
        // Related work by Samosky is in:
        //
        // Samosky, Joseph, "SectionView: A system for interactively specifying and
        // visualizing sections through three-dimensional medical image data",
        // M.S. Thesis, Department of Electrical Engineering and Computer Science,
        // Massachusetts Institute of Technology, 1993.
        //
        // Shoot a test ray along +X axis.  The strategy is to compare vertex Y values
        // to the testing point's Y and quickly discard edges which are entirely to one
        // side of the test ray.  Note that CONVEX and WINDING code can be added as
        // for the CrossingsTest() code; it is left out here for clarity.
        //
        // Input 2D polygon _pgon_ with _numverts_ number of vertices and test point
        // _point_, returns 1 if inside, 0 if outside.
        public static bool IsPointInVxs(PixelFarm.Drawing.VertexStore vxs, double tx, double ty)
        {
            int m_num_points = vxs.Count;

            if (m_num_points < 3)
            {
                return(false);
            }
            // if (!m_in_polygon_check) return false;

            int    j;
            bool   yflag0, yflag1, inside_flag;
            double vtx0, vty0, vtx1, vty1;

            vxs.GetVertex(m_num_points - 1, out vtx0, out vty0);
            //vtx0 = GetXN(m_num_points - 1);
            //vty0 = GetYN(m_num_points - 1);

            // get test bit for above/below X axis
            yflag0 = (vty0 >= ty);
            //vtx1 = GetXN(0);
            //vty1 = GetYN(0);
            vxs.GetVertex(0, out vtx1, out vty1);
            inside_flag = false;
            for (j = 1; j <= m_num_points; ++j)
            {
                yflag1 = (vty1 >= ty);
                // Check if endpoints straddle (are on opposite sides) of X axis
                // (i.e. the Y's differ); if so, +X ray could intersect this edge.
                // The old test also checked whether the endpoints are both to the
                // right or to the left of the test point.  However, given the faster
                // intersection point computation used below, this test was found to
                // be a break-even proposition for most polygons and a loser for
                // triangles (where 50% or more of the edges which survive this test
                // will cross quadrants and so have to have the X intersection computed
                // anyway).  I credit Joseph Samosky with inspiring me to try dropping
                // the "both left or both right" part of my code.
                if (yflag0 != yflag1)
                {
                    // Check intersection of pgon segment with +X ray.
                    // Note if >= point's X; if so, the ray hits it.
                    // The division operation is avoided for the ">=" test by checking
                    // the sign of the first vertex wrto the test point; idea inspired
                    // by Joseph Samosky's and Mark Haigh-Hutchinson's different
                    // polygon inclusion tests.
                    if (((vty1 - ty) * (vtx0 - vtx1) >=
                         (vtx1 - tx) * (vty0 - vty1)) == yflag1)
                    {
                        inside_flag = !inside_flag;
                    }
                }

                // Move to the next pair of vertices, retaining info as possible.
                yflag0 = yflag1;
                vtx0   = vtx1;
                vty0   = vty1;
                int k = (j >= m_num_points) ? j - m_num_points : j;
                //vtx1 = GetXN(k);
                //vty1 = GetYN(k);
                vxs.GetVertex(k, out vtx1, out vty1);
            }
            return(inside_flag);
        }
Example #5
0
        public void RenderChar(char testChar, HintTechnique hint)
        {
            builder.SetHintTechnique(hint);
#if DEBUG
            GlyphBoneJoint.dbugTotalId        = 0;//reset
            builder.dbugAlwaysDoCurveAnalysis = true;
#endif
            _infoView.Clear();
            _latestHint = hint;
            _testChar   = testChar;
            //----------------------------------------------------
            //
            builder.Build(testChar, _sizeInPoint);
            var txToVxs1 = new GlyphTranslatorToVxs();
            builder.GlyphDynamicEdgeOffset = this.GlyphEdgeOffset;

            builder.ReadShapes(txToVxs1);

#if DEBUG
            var ps = txToVxs1.dbugGetPathWriter();
            _infoView.ShowOrgBorderInfo(ps.Vxs);
#endif
            PixelFarm.Drawing.VertexStore vxs = new PixelFarm.Drawing.VertexStore();

            txToVxs1.WriteOutput(vxs);
            //----------------------------------------------------

            //----------------------------------------------------
            painter.UseSubPixelLcdEffect = this.UseLcdTechnique;
            //5. use PixelFarm's Agg to render to bitmap...
            //5.1 clear background
            painter.Clear(PixelFarm.Drawing.Color.White);

            RectD bounds = RectD.ZeroIntersection;
            PixelFarm.CpuBlit.VertexProcessing.BoundingRect.GetBoundingRect(new PixelFarm.Drawing.VertexStoreSnap(vxs), ref bounds);
            //----------------------------------------------------
            float scale = _typeface.CalculateScaleToPixelFromPointSize(_sizeInPoint);
            _pxscale = scale;
            this._infoView.PxScale = scale;


            var   left2   = 0;
            int   floor_1 = (int)left2;
            float diff    = left2 - floor_1;
            //----------------------------------------------------
            if (OffsetMinorX)
            {
                MinorOffsetInfo = left2.ToString() + " =>" + floor_1 + ",diff=" + diff;
            }
            else
            {
                MinorOffsetInfo = left2.ToString();
            }


            //5. use PixelFarm's Agg to render to bitmap...
            //5.1 clear background
            painter.Clear(PixelFarm.Drawing.Color.White);

            if (FillBackGround)
            {
                //5.2
                painter.FillColor = PixelFarm.Drawing.Color.Black;

                float xpos = 5;// - diff;
                if (OffsetMinorX)
                {
                    xpos -= diff;
                }

                painter.SetOrigin(xpos, 10);
                painter.Fill(vxs);
            }
            if (DrawBorder)
            {
                //5.4
                painter.StrokeColor = PixelFarm.Drawing.Color.Green;
                //user can specific border width here...
                //5.5
                painter.Draw(vxs);
                //--------------
                int    markOnVertexNo = _infoView.DebugMarkVertexCommand;
                double x, y;
                vxs.GetVertex(markOnVertexNo, out x, out y);
                painter.FillRect(x, y, 4, 4, PixelFarm.Drawing.Color.Red);
                //--------------
                _infoView.ShowFlatternBorderInfo(vxs);
                //--------------
            }
#if DEBUG
            builder.dbugAlwaysDoCurveAnalysis = false;
#endif

            if (ShowTess)
            {
                RenderTessTesult();
            }

            //if (DrawDynamicOutline)
            //{
            //    GlyphDynamicOutline dynamicOutline = builder.LatestGlyphFitOutline;
            //    WalkDynamicOutline(painter, dynamicOutline, scale, DrawRegenerateOutline);

            //}
        }