コード例 #1
0
        internal void Init(com.epl.geometry.MultiVertexGeometryImpl geom, double toleranceXY, int rasterSizeBytes)
        {
            // _ASSERT(CanUseAccelerator(geom));
            m_width        = System.Math.Max((int)(System.Math.Sqrt(rasterSizeBytes) * 2 + 0.5), 64);
            m_scanLineSize = (m_width * 2 + 31) / 32;
            // 2 bits per pixel
            m_geomEnv     = new com.epl.geometry.Envelope2D();
            m_toleranceXY = toleranceXY;
            // calculate bitmap size
            int size         = 0;
            int width        = m_width;
            int scanLineSize = m_scanLineSize;

            while (width >= 8)
            {
                size        += width * scanLineSize;
                width       /= 2;
                scanLineSize = (width * 2 + 31) / 32;
            }
            // allocate the bitmap, that contains the base and the mip-levels
            m_bitmap = new int[size];
            for (int i = 0; i < size; i++)
            {
                m_bitmap[i] = 0;
            }
            m_rasterizer = new com.epl.geometry.SimpleRasterizer();
            com.epl.geometry.RasterizedGeometry2DImpl.ScanCallbackImpl callback = new com.epl.geometry.RasterizedGeometry2DImpl.ScanCallbackImpl(this, m_bitmap, m_scanLineSize);
            m_callback = callback;
            m_rasterizer.Setup(m_width, m_width, callback);
            geom.QueryEnvelope2D(m_geomEnv);
            if (m_geomEnv.GetWidth() > m_width * m_geomEnv.GetHeight() || m_geomEnv.GetHeight() > m_geomEnv.GetWidth() * m_width)
            {
            }
            // the geometry is thin and the rasterizer is not needed.
            m_geomEnv.Inflate(toleranceXY, toleranceXY);
            com.epl.geometry.Envelope2D worldEnv = new com.epl.geometry.Envelope2D();
            com.epl.geometry.Envelope2D pixEnv   = com.epl.geometry.Envelope2D.Construct(1, 1, m_width - 2, m_width - 2);
            double minWidth = toleranceXY * pixEnv.GetWidth();
            // min width is such
            // that the size of
            // one pixel is
            // equal to the
            // tolerance
            double minHeight = toleranceXY * pixEnv.GetHeight();

            worldEnv.SetCoords(m_geomEnv.GetCenter(), System.Math.Max(minWidth, m_geomEnv.GetWidth()), System.Math.Max(minHeight, m_geomEnv.GetHeight()));
            m_stroke_half_widthX_pix = worldEnv.GetWidth() / pixEnv.GetWidth();
            m_stroke_half_widthY_pix = worldEnv.GetHeight() / pixEnv.GetHeight();
            // The stroke half width. Later it will be inflated to account for
            // pixels size.
            m_stroke_half_width = m_toleranceXY;
            m_transform         = new com.epl.geometry.Transformation2D();
            m_transform.InitializeFromRect(worldEnv, pixEnv);
            // geom to pixels
            com.epl.geometry.Transformation2D identityTransform = new com.epl.geometry.Transformation2D();
            switch (geom.GetType().Value())
            {
            case com.epl.geometry.Geometry.GeometryType.MultiPoint:
            {
                callback.SetColor(m_rasterizer, 2);
                FillPoints(m_rasterizer, (com.epl.geometry.MultiPointImpl)geom, m_stroke_half_width);
                break;
            }

            case com.epl.geometry.Geometry.GeometryType.Polyline:
            {
                callback.SetColor(m_rasterizer, 2);
                StrokeDrawPolyPath(m_rasterizer, (com.epl.geometry.MultiPathImpl)geom._getImpl(), m_stroke_half_width);
                break;
            }

            case com.epl.geometry.Geometry.GeometryType.Polygon:
            {
                bool isWinding = false;
                // NOTE: change when winding is supported
                callback.SetColor(m_rasterizer, 1);
                FillMultiPath(m_rasterizer, m_transform, (com.epl.geometry.MultiPathImpl)geom, isWinding);
                callback.SetColor(m_rasterizer, 2);
                StrokeDrawPolyPath(m_rasterizer, (com.epl.geometry.MultiPathImpl)geom._getImpl(), m_stroke_half_width);
                break;
            }
            }
            m_dx = m_transform.xx;
            m_dy = m_transform.yy;
            m_x0 = m_transform.xd;
            m_y0 = m_transform.yd;
            BuildLevels();
        }