Package com.bbn.openmap.omGraphics

Examples of com.bbn.openmap.omGraphics.OMRaster


        // image icon is no good.
        if (bi == null && it == null) {
            return list;
        }

        OMRaster ras = null;

        if (it == null) {
            it = new ImageTranslator(bi);
            bi = null; // don't hold onto it.
        }
View Full Code Here


                    }
                }

                Debug.message("earthimage",
                        "ImageTranslator: finished creating image");
                return new OMRaster(0, 0, projWidth, projHeight, tmpPixels);
            } else {
                Debug.message("earthimage",
                        "ImageTranslator: problem creating image");
            }
View Full Code Here

     *
     * @param myPoint
     */
    protected OMGraphic createPoint(MysqlPoint myPoint) {
        ImageIcon actualPointSymbol = new ImageIcon(pointSymbol);
        OMRaster ompoint = new OMRaster((float) myPoint.getNorthings(), (float) myPoint.getEastings(), actualPointSymbol);

        drawingAttributes.setTo(ompoint);

        return ompoint;
    }
View Full Code Here

     * Called from within generate to create an OMRaster object for
     * the OMGrid. This method exists to make it easier to extend this
     * class to create an OMRaster as needed.
     */
    protected OMRaster getRaster(OMGrid grid) {
        return new OMRaster(grid.point1.x, grid.point1.y, grid.width, grid.height, new int[grid.width
                * grid.height]);
    }
View Full Code Here

                Debug.output("SlopeGenerator: OMGrid does not overlap map, skipping generation.");
            }
            return SinkGraphic.getSharedInstance();
        }

        OMRaster raster = getRaster(grid);
        incomplete = false;

        if (grid.height == 0 || grid.width == 0) {
            Debug.message("grid", "SlopeGenerator: grid height/width ZERO!");
            return raster;
        }

        GridData gd = grid.getData();

        if (!(gd instanceof GridData.Short)) {
            Debug.message("grid",
                    "SlopeGenerator: grid doesn't contain short data.");
            return SinkGraphic.getSharedInstance();
        }

        int rows = grid.getRows();
        int columns = grid.getColumns();
        short[][] data = ((GridData.Short) gd).getData();
//        boolean major = grid.getMajor();

        double distance = getSlopeRun(grid, getContrast());

        // Used for projections of image coordinates. Reused in the
        // loops to save memory.
        LatLonPoint llp = new LatLonPoint();
        Point point = new Point();
        ElevationColors colors = getColors();

        if (colors == null) {
            return SinkGraphic.getSharedInstance();
        }

        // x is the horizontal pixel being modified
        for (short x = 0; x < grid.width; x++) {
            // Check to make sure the pixels we're calculating are on
            // the map.
            int screenx = (int) grid.point1.getX() + x;
            if (screenx < 0 || screenx > proj.getWidth()) {
                incomplete = true;
                continue;
            }

            for (short y = 0; y < grid.height; y++) {

                // Check to make sure the pixels we're calculating are
                // on the map.
                int screeny = (int) grid.point1.getY() + y;
                if (screeny < 0 || screeny > proj.getHeight()) {
                    incomplete = true;
                    continue;
                }

                // OK, on the map.
                point.setLocation(screenx, screeny);
                llp = proj.inverse(point.x, point.y, llp);

                int yc = Math.round((llp.getLatitude() - grid.getLatitude())
                        / grid.getVerticalResolution());
                int xc = Math.round((llp.getLongitude() - grid.getLongitude())
                        / grid.getHorizontalResolution());

                // If the calculated index is out of the data ranges,
                // push it to the end. Don't blow it off, it will
                // cause unfilled data pixel lines to appear. You
                // only want to blow off pixels that are not on the
                // map, or are never going to be on the map.
                if (yc < 0)
                    yc = 0;
                if (yc > rows - 1)
                    yc = rows - 1;
                if (xc < 0)
                    xc = 0;
                if (xc > columns - 1)
                    xc = columns - 1;

                int elevation = 0;

                // Otherwise, get the elevation for the data point.
                try {
                    elevation = (int) data[xc][yc];
                } catch (ArrayIndexOutOfBoundsException aioobe) {
                    Debug.output("Error Accessing data array:\n\txc: " + xc
                            + ", yc: " + yc + " for x: " + x + ", y: " + y);
                }

                // Slope shading calculations, get the upper left and
                // lower right data points.

                int xnw = xc - 1;
                int xse = xc + 1;
                // trying to smooth out the edge of the frame
                if (xc == 0 || xnw < 0) {
                    xnw = xc;
                }
                if (xc == columns - 1 || xse > columns - 1) {
                    xse = columns - 1;
                }

                int yse = yc - 1;
                int ynw = yc + 1;
                //  trying to smooth out the edge of the frame by
                // handling the
                //  frame limits
                if (yse < 0) {
                    yse = 0;
                }
                if (yc == rows - 1 || ynw > rows - 1) {
                    ynw = rows - 1;
                }

                // Get the elevation points for the slope measurement
                // points.
                try {
                    short e2 = data[xse][yse]; // down & right
                    // elevation
                    short e1 = data[xnw][ynw]; // up and left
                    // elevation

                    // colormap value darker for negative slopes,
                    // brighter for
                    // positive slopes.
                    // slope relative to nw sun
                    double slope = (e2 - e1) / distance;

                    raster.setPixel(x, y, colors.getARGB(elevation,
                            grid.getUnits(),
                            slope));

                } catch (ArrayIndexOutOfBoundsException aioobe) {
                    Debug.output("Error Accessing data array:\n\txse: " + xse
                            + ", yse: " + yse + "\n\txnw: " + xnw + ", ynw: "
                            + ynw + "\n\tfor x: " + x + ", y: " + y);
                }
            }
        }

        raster.generate(proj);
        if (Debug.debugging("grid"))
            Debug.output("SlopeGenerator: leaving generate");
        return raster;
    }
View Full Code Here

            Debug.message("grid",
                    "SimpleColorGenerator: grid height/width ZERO!");
            return SinkGraphic.getSharedInstance();
        }

        OMRaster raster = new OMRaster(grid.point1.x, grid.point1.y, grid.width, grid.height, new int[grid.width
                * grid.height]);

        int rows = grid.getRows();
        int columns = grid.getColumns();
        RasterHelper rasterHelper = getRasterHelper(grid.getData());
        boolean major = grid.getMajor();

        /** lat and lon_intervals are grid point/pixel.. */
        double y_interval = (double) rows / (double) grid.height;
        double x_interval = (double) columns / (double) grid.width;

        Debug.message("grid", "SimpleColorGenerator: y_point_interval = "
                + y_interval + ", x_point_interval = " + x_interval);

        /**
         * Right now, if the rendertype of the grid is RENDERTYPE_LATLON, we
         * limit sensible rendering to the CADRG/LLXY projections. No warping
         * done.
         */

        int post_x, post_y, value;
        /** Do this pixel by pixel. */
        for (int x = 0; x < grid.width; x++) {
            for (int y = 0; y < grid.height; y++) {

                post_x = (int) Math.round(x_interval * (double) x);
                if (grid.getRenderType() == OMGraphic.RENDERTYPE_LATLON) {
                    post_y = (int) Math.round(y_interval
                            * (grid.height - 1 - (double) y));
                } else {
                    post_y = (int) Math.round(y_interval * (double) y);
                }

                if (major == OMGrid.COLUMN_MAJOR) {
                    if (post_x >= columns)
                        post_x = columns - 1;
                    if (post_y >= rows)
                        post_y = rows - 1;

                    value = calibratePointValue(rasterHelper.get(post_x, post_y));
                } else {
                    if (post_y >= columns)
                        post_y = columns - 1;
                    if (post_x >= rows)
                        post_x = rows - 1;

                    value = calibratePointValue(rasterHelper.get(post_y, post_x));
                }

                raster.setPixel(x, y, value);
            }
        }
        raster.generate(proj);

        return raster;
    }
View Full Code Here

     * visually. The appropriate method may be to have Projection.inverse and
     * its variants raise an exception for "Outer Space" values.
     */
    protected OMRaster buildRaster() {
        // initialize the return
        OMRaster ret = null;
        Projection projection = getProjection();
        // work with the slopeMap
        if (slopeMap != null) {

            // compute our deltas
            int width = projection.getWidth();
            int height = projection.getHeight();

            // create int array to hold colors
            int[] colors = new int[width * height];

            // compute scalers for lat/lon indicies
            float scy = (float) bufferHeight / 180F;
            float scx = (float) bufferWidth / 360F;

            // starting and ending indices
            int sx = 0, sy = 0, ex = width, ey = height;

            // handle CADRG
            if (projection instanceof CADRG) {

                // get corners
                LatLonPoint ul = projection.getUpperLeft();
                LatLonPoint lr = projection.getLowerRight();

                // set start/end indicies
                Point ulp = projection.forward(ul);
                Point lrp = projection.forward(lr);
                sx = (int) ulp.getX();
                ex = (int) lrp.getX();
                sy = (int) ulp.getY();
                ey = (int) lrp.getY();

            }

            // get the center lat/lon (used by the HACK, see above in
            // method description)
            LatLonPoint center = projection.getCenter();
            LatLonPoint llp = new LatLonPoint();
            // build array
            for (int y = sy; y < ey; y++) {

                // process each column
                for (int x = sx; x < ex; x++) {

                    // inverse project x,y to lon,lat
                    projection.inverse(x, y, llp);

                    // get point values
                    float lat = llp.getLatitude();
                    float lon = llp.getLongitude();

                    // check... dfd
                    if (minuteSpacing == 2) {
                        lon += 180.;
                    } else {
                        if (lon < 0.)
                            lon += 360.;
                    }

                    // find indicies
                    int lat_idx = (int) ((90. - lat) * scy);
                    int lon_idx = (int) (lon * scx);

                    // offset
                    int ofs = lon_idx + lat_idx * bufferWidth;

                    // make a color
                    int idx = 0;
                    int gray = 0;
                    try {

                        // get elevation
                        short el = dataBuffer[ofs];

                        // slope
                        byte sl = slopeMap[ofs];

                        // our index
                        idx = y * width + x;

                        // create a color
                        Color pix = null;
                        if (viewType == SLOPESHADING) {
                            // HACK (see method description above)
                            if ((llp.getLatitude() == center.getLatitude())
                                    && (llp.getLongitude() == center.getLongitude()))
                                gray = 0;
                            else
                                gray = 127 + sl;
                            pix = new Color(gray, gray, gray, opaqueness);
                        } else if (viewType == COLOREDSHADING) {
                            // HACK (see method description above)
                            if ((llp.getLatitude() == center.getLatitude())
                                    && (llp.getLongitude() == center.getLongitude()))
                                pix = new Color(0, 0, 0, opaqueness);
                            else
                                pix = getColor(el, sl);
                        }

                        // set
                        colors[idx] = pix.getRGB();

                    }

                    // tried to set a bad color level
                    catch (IllegalArgumentException e) {
                        Debug.error(e.toString() + ":" + gray);
                    }

                    // bad index
                    catch (ArrayIndexOutOfBoundsException e) {
                        Debug.error(e.toString() + ":" + idx);
                    }
                }
            }

            // create the raster
            ret = new OMRaster(0, 0, width, height, colors);

        }

        // return or raster
        return ret;
View Full Code Here

     */
    public static OMRaster read(DataInputStream dis,
                                LinkProperties propertiesBuffer)
            throws IOException {

        OMRaster raster = null;
        float lat = 0;
        float lon = 0;
        int x = 0;
        int y = 0;
        int w = 0;
        int h = 0;
        int length, i;
        String url;

        Debug.message("link", "LinkRaster | Reading Raster graphic");

        int renderType = dis.readByte();
        int colorModel = dis.readByte();

        if (Debug.debugging("link")) {
            System.out.println("LinkRaster | Rendertype = " + renderType
                    + ", colorModel = " + colorModel);
        }

        switch (renderType) {
        case RENDERTYPE_OFFSET:
            lat = dis.readFloat();
            lon = dis.readFloat();
            // Fall through...
        case RENDERTYPE_XY:
            x = dis.readInt();
            y = dis.readInt();
            break;
        case RENDERTYPE_LATLON:
        default:
            lat = dis.readFloat();
            lon = dis.readFloat();
            if (Debug.debugging("link")) {
                System.out.println("LinkRaster | Location: lat = " + lat
                        + ", lon = " + lon);
            }
        }

        // Now act differently depending on the colormodel
        if (colorModel != COLORMODEL_URL) {

            w = dis.readInt();
            h = dis.readInt();

            if (Debug.debugging("link")) {
                System.out.println("LinkRaster | Size: width = " + w
                        + ", height = " + h);
            }

            if (colorModel == COLORMODEL_INDEXED) {

                length = dis.readInt();

                byte[] bytes = new byte[length];

                if (Debug.debugging("link")) {
                    System.out.println("LinkRaster | Reading " + length
                            + " bytes.");
                }
                dis.readFully(bytes);

                if (Debug.debugging("link")) {
                    System.out.println("LinkRaster | read bytes.");
                }

                length = dis.readInt();

                if (Debug.debugging("link")) {
                    System.out.println("LinkRaster | " + length + " Colors.");
                }

                Color[] colorTable = new Color[length];
                for (i = 0; i < length; i++) {
                    int colorvalue = dis.readInt();
                    colorTable[i] = ColorFactory.createColor(colorvalue, true);
                    if (Debug.debugging("linkdetail")) {
                        System.out.println("LinkRaster | Color " + i + " =  "
                                + colorTable[i] + " from "
                                + Integer.toHexString(colorvalue));
                    }
                }

                int trans = dis.readInt();
                if (Debug.debugging("link")) {
                    System.out.println("LinkRaster | Transparency =  " + trans);
                }

                switch (renderType) {
                case RENDERTYPE_OFFSET:
                    raster = new OMRaster(lat, lon, x, y, w, h, bytes, colorTable, trans);
                    break;
                case RENDERTYPE_XY:
                    raster = new OMRaster(x, y, w, h, bytes, colorTable, trans);
                    break;
                case RENDERTYPE_LATLON:
                default:
                    raster = new OMRaster(lat, lon, w, h, bytes, colorTable, trans);
                }

            } else { // must be COLORMODEL_DIRECT
                length = dis.readInt();
                int[] pix = new int[length];
                if (Debug.debugging("link")) {
                    System.out.println("LinkRaster | Reading " + length
                            + " pixels.");
                }

                for (i = 0; i < length; i++) {
                    pix[i] = dis.readInt();
                }
                switch (renderType) {
                case RENDERTYPE_OFFSET:
                    raster = new OMRaster(lat, lon, x, y, w, h, pix);
                    break;
                case RENDERTYPE_XY:
                    raster = new OMRaster(x, y, w, h, pix);
                    break;
                case RENDERTYPE_LATLON:
                default:
                    raster = new OMRaster(lat, lon, w, h, pix);
                }
            }
        }

        LinkProperties properties = (LinkProperties) LinkProperties.read(dis, propertiesBuffer).clone();

        if (colorModel == COLORMODEL_URL) {
            url = properties.getProperty(LPC_LINKRASTERIMAGEURL);

            if (url != null) {
                switch (renderType) {
                case RENDERTYPE_OFFSET:
                    raster = new OMRaster(lat, lon, x, y, new ImageIcon(url));
                    break;
                case RENDERTYPE_XY:
                    raster = new OMRaster(x, y, new ImageIcon(url));
                    break;
                case RENDERTYPE_LATLON:
                default:
                    raster = new OMRaster(lat, lon, new ImageIcon(url));
                }
            }
        }

        if (raster != null) {
            properties.setProperties(raster);
            raster.setRotationAngle((double) ProjMath.degToRad(PropUtils.floatFromProperties(properties,
                    LPC_LINKROTATION,
                    0.0f)));
        }

        return raster;
View Full Code Here

        if (!isDirectColorModel) {
            if (DEBUG_RPFDETAIL) {
                Debug.output("RpfFrame: decompress to byte[]");
            }
            byte[] pixels = decompressSubframe(x, y);
            OMRaster image = subframe.image;
            image.setBits(pixels);
            image.setColors(colortable.colors);
        } else {
            int[] pixels = decompressSubframe(x, y, colortable);
            OMRaster image = subframe.image;
            image.setPixels(pixels);
        }
        return subframe;
    }
View Full Code Here

     "Outer Space" values.
     *
     */
    protected OMRaster buildRaster() {
        // initialize the return
        OMRaster ret = null;
        Projection projection = getProjection();
        // work with the slopeMap
        if (slopeMap != null) {
           
            // compute our deltas
            int pixelColumns = projection.getWidth();
            int pixelRows = projection.getHeight();

            // create int array to hold colors
            int[] colors = new int[pixelColumns * pixelRows];

            // compute scalers for lat/lon indicies
            float yPixPerDataPt = (float) bufferHeight / 180F;
            float xPixPerDataPt = (float) bufferWidth / 360F;

            // starting and ending indices
            int sx = 0, sy = 0, ex = pixelColumns, ey = pixelRows;

            // handle CADRG
            if (projection instanceof CADRG) {

                                // get corners
                LatLonPoint ul = projection.getUpperLeft();
                LatLonPoint lr = projection.getLowerRight();

                                // set start/end indicies
                Point ulp = projection.forward(ul);
                Point lrp = projection.forward(lr);
                sx = (int) ulp.getX();
                ex = (int) lrp.getX();
                sy = (int) ulp.getY();
                ey = (int) lrp.getY();

            }

            // get the center lat/lon (used by the HACK, see above in
            // method description)
            LatLonPoint center = projection.getCenter();
            LatLonPoint llp = new LatLonPoint();

            // build array
            float lat;
            float lon;
            int lat_idx;
            int lon_idx;
            float latWt;
            float lonWt;

            // offset
            int ofs;
            int ofsRight;
            int ofsDown;
            int ofsDownRight;

            for (int y = sy; y < ey; y++) {


                                // process each column
                for (int x = sx; x < ex; x++) {

                    // inverse project x,y to lon,lat
                    projection.inverse(x, y, llp);

                    // get point values
                    lat = llp.getLatitude();
                    lon = llp.getLongitude();

                    // check
                    if (lon < 0.) {
                        lon += 360.;
                    }

                    // find indicies
                    lat_idx = (int) ((90. - lat) * yPixPerDataPt);
                    lon_idx = (int) (lon * xPixPerDataPt);

                    // most pixels fall between data points. The data
                    // point originally used is the one immediately
                    // above and to the left of the pixel. The amount
                    // by which the pixel is offset from the data
                    // point can be used to weight the elevation
                    // contribution of the four data points
                    // surrounding the pixel ie. the weights. The
                    // truncated decimal part of the index computation
                    // is the weight.
                    latWt = ((90f - lat) * yPixPerDataPt) - (float) lat_idx;
                    lonWt = (lon * xPixPerDataPt) - (float) lon_idx;

                    // offsets of the four surrounding data points.
                    ofs = lon_idx + lat_idx * bufferWidth;
                    ofsRight = ofs + 1;
                    if (lat_idx+1 < bufferHeight) {
                        ofsDown = lon_idx + (1 + lat_idx) * bufferWidth;
                    } else {
                        ofsDown = ofs;
                    }
                    ofsDownRight = ofsDown + 1;

                    // make a color
                    int idx = 0;
                    int gray = 0;
                    short el = 0;
                    byte sl = 0;

                    try {

                        try {
                            float ulwt = (1f - lonWt + 1f - latWt);
                            float urwt = (lonWt + 1f - latWt);
                            float llwt = (1f - lonWt + latWt);
                            float lrwt = (lonWt + latWt);
                            // get elevation
                            el =
                                (short) ((float) dataBuffer[ofs] * ulwt
                                         + (float) dataBuffer[ofsRight] * urwt
                                         + (float) dataBuffer[ofsDown] * llwt
                                         + (float) dataBuffer[ofsDownRight] * lrwt);

                            // slope
                            sl =
                                (byte) ((float) slopeMap[ofs] * ulwt
                                        + (float) slopeMap[ofsRight] * urwt
                                        + (float) slopeMap[ofsDown] * llwt
                                        + (float) slopeMap[ofsDownRight] * lrwt);
                            float exagFactor = 1f/ (el > 0?1.5f:3f);
                            el = (short)((float)el * exagFactor);
                            sl = (byte)((float)sl * exagFactor);

                            // bad index
                        } catch (ArrayIndexOutOfBoundsException e) {
                            Debug.error(e.toString() + ":" +
                                        ofs + " limit=" +
                                        dataBuffer.length);
                        }
                        // our index
                        idx = y * pixelColumns + x;

                        // create a color
                        Color pix = null;
                        if (viewType == SLOPESHADING) {
                            // HACK (see method description above)
                            if ((llp.getLatitude() == center.getLatitude())
                                && (llp.getLongitude() == center.getLongitude()))
                                gray = 0;
                            else
                                gray = 127 + sl;
                            pix = new Color(gray, gray, gray, opaqueness);
                        } else if (viewType == COLOREDSHADING) {
                            // HACK (see method description above)
                            if ((llp.getLatitude() == center.getLatitude())
                                && (llp.getLongitude() == center.getLongitude()))
                                pix = new Color(0, 0, 0, opaqueness);
                            else
                                pix = getColor(el, sl);
                        }

                        // set
                        colors[idx] = pix.getRGB();
                       
                    }
                   
                    // tried to set a bad color level
                    catch (IllegalArgumentException e) {
                        Debug.error(e.toString() + ":" + gray);
                    }
                   
                    // bad index
                    catch (ArrayIndexOutOfBoundsException e) {
                        Debug.error(e.toString() + ":" + idx);
                    }
                }
            }

            // create the raster
            ret = new OMRaster(0, 0, pixelColumns, pixelRows, colors);

        }

        // return or raster
        return ret;
View Full Code Here

TOP

Related Classes of com.bbn.openmap.omGraphics.OMRaster

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.