Example usage for java.awt.geom Rectangle2D getMaxY

List of usage examples for java.awt.geom Rectangle2D getMaxY

Introduction

In this page you can find the example usage for java.awt.geom Rectangle2D getMaxY.

Prototype

public double getMaxY() 

Source Link

Document

Returns the largest Y coordinate of the framing rectangle of the Shape in double precision.

Usage

From source file:org.mrgeo.utils.Bounds.java

public Bounds(Rectangle2D from) {
    minX = from.getMinX();
    minY = from.getMinY();
    maxX = from.getMaxX();
    maxY = from.getMaxY();

    set = true;
}

From source file:org.n52.oxf.serialization.XmlBeansContextWriter.java

private void serialize(ContextBoundingBox bboxToSerialize) {
    Rectangle2D actualBBox = bboxToSerialize.getActualBBox();
    BoundingBoxType xb_bbox = BoundingBoxType.Factory.newInstance();
    xb_bbox.setMaxx(new BigDecimal(actualBBox.getMaxX()));
    xb_bbox.setMinx(new BigDecimal(actualBBox.getMinX()));
    xb_bbox.setMaxy(new BigDecimal(actualBBox.getMaxY()));
    xb_bbox.setMiny(new BigDecimal(actualBBox.getMinY()));
    xb_bbox.setSRS(bboxToSerialize.getSRS());
    builder.append(xb_bbox.toString());//from  www . ja v a2s  . c  om
}

From source file:org.opensha.commons.geo.GriddedRegion.java

private List<Integer> indexLookupFast(Rectangle2D rect) {
    checkArgument(area.contains(rect));// w w w .  j  a  v a2 s  . c o  m
    Location pLL = new Location(rect.getMinY(), rect.getMinX());
    Location pUL = new Location(rect.getMaxY(), rect.getMinX());
    Location pLR = new Location(rect.getMinY(), rect.getMaxX());
    int idxLL = indexForLocation(pLL);
    int idxUL = indexForLocation(pUL);
    int idxLR = indexForLocation(pLR);

    // indices of row starts
    List<Integer> rowStarts = Lists.newArrayList();
    int rowStartIdx = idxLL;
    int lastRowStartIdx = idxUL;
    while (rowStartIdx <= lastRowStartIdx) {
        rowStarts.add(rowStartIdx);
        Location currLoc = locationForIndex(rowStartIdx);
        Location nextLoc = new Location(currLoc.getLatitude() + latSpacing, currLoc.getLongitude());
        rowStartIdx = indexForLocation(nextLoc);
    }

    // row length
    int len = idxLR - idxLL + 1;

    // build list
    List<Integer> indices = Lists.newArrayList();
    for (Integer idx : rowStarts) {
        addRange(indices, idx, len);
    }
    return indices;

}

From source file:org.orbisgis.view.map.tools.InfoTool.java

@Override
protected void rectangleDone(Rectangle2D rect, boolean smallerThanTolerance, MapContext vc, ToolManager tm)
        throws TransitionException {
    ILayer layer = vc.getSelectedLayers()[0];
    DataSource sds = layer.getDataSource();

    try {//from   w  w  w .j  a v a 2s .co  m
        double minx = rect.getMinX();
        double miny = rect.getMinY();
        double maxx = rect.getMaxX();
        double maxy = rect.getMaxY();
        BackgroundManager bm = Services.getService(BackgroundManager.class);
        bm.backgroundOperation(new DefaultJobId("org.orbisgis.jobs.InfoTool"),
                new PopulateViewJob(new Envelope(minx, maxx, miny, maxy), sds));
    } catch (DriverLoadException e) {
        throw new RuntimeException(e);
    }
}

From source file:org.photovault.image.ImageOpChain.java

/**
 * Helper function to apply Photovault style cropping to this chain
 * @param cropBounds Crop bounds.//from   w  w w  .  j  ava 2 s . co  m
 */
public void applyCropping(Rectangle2D cropBounds) {
    CropOp crop = (CropOp) getOperation("crop");
    if (crop == null) {
        crop = createCropOp();
    }
    crop.setMinX(cropBounds.getMinX());
    crop.setMaxX(cropBounds.getMaxX());
    crop.setMinY(cropBounds.getMinY());
    crop.setMaxY(cropBounds.getMaxY());
}

From source file:org.photovault.image.PhotovaultImage.java

/**
 Set new crop bounds for the image. Crop bounds are applied after rotation,
 so that top left corner is (0, 0) and bottom right corner (1, 1)
 @param c New crop bounds/*from  w ww . j  av  a2 s.  c  om*/
 */
public void setCropBounds(Rectangle2D c) {
    cropMinX = Math.min(1.0, Math.max(0.0, c.getMinX()));
    cropMinY = Math.min(1.0, Math.max(0.0, c.getMinY()));
    cropMaxX = Math.min(1.0, Math.max(0.0, c.getMaxX()));
    cropMaxY = Math.min(1.0, Math.max(0.0, c.getMaxY()));

    if (cropMaxX - cropMinX <= 0.0) {
        double tmp = cropMaxX;
        cropMaxX = cropMinX;
        cropMinX = tmp;
    }
    if (cropMaxY - cropMinY <= 0.0) {
        double tmp = cropMaxY;
        cropMaxY = cropMinY;
        cropMinY = tmp;
    }
    applyRotCrop();
}

From source file:org.photovault.imginfo.ChangePhotoInfoCommand.java

/**
 Execute the command./*from  w  w w .  ja  v  a 2  s  .  c  om*/
 */
public void execute() throws CommandException {
    StringBuffer debugMsg = null;
    if (log.isDebugEnabled()) {
        debugMsg = new StringBuffer();
        debugMsg.append("execute()");
        boolean isFirst = true;
        for (UUID id : photoUuids) {
            debugMsg.append(isFirst ? "Photo ids: " : ", ");
            debugMsg.append(id);
        }
        debugMsg.append("\n");
        debugMsg.append("Changed values:\n");
        for (Map.Entry<String, Object> e : changedFields.entrySet()) {
            String field = e.getKey();
            Object value = e.getValue();
            debugMsg.append(field).append(": ").append(value).append("\n");
        }
        log.debug(debugMsg);
    }
    PhotoInfoDAO photoDAO = daoFactory.getPhotoInfoDAO();
    Set<PhotoInfo> photos = new HashSet<PhotoInfo>();
    if (photoUuids.size() == 0) {
        PhotoInfo photo = photoDAO.create();
        photos.add(photo);
    } else {
        for (UUID id : photoUuids) {
            PhotoInfo photo = photoDAO.findByUUID(id);
            photos.add(photo);
        }
    }
    changedPhotos = new HashSet<PhotoInfo>();
    Set<PhotoInfoFields> rawSettingsFields = EnumSet.range(PhotoInfoFields.RAW_BLACK_LEVEL,
            PhotoInfoFields.RAW_COLOR_PROFILE);
    Set<PhotoInfoFields> colorCurveFields = EnumSet.range(PhotoInfoFields.COLOR_CURVE_VALUE,
            PhotoInfoFields.COLOR_CURVE_SATURATION);
    Set<PhotoInfoFields> cropFields = EnumSet.of(PhotoInfoFields.CROP_BOUNDS, PhotoInfoFields.PREF_ROTATION);

    DTOResolverFactory resolverFactory = daoFactory.getDTOResolverFactory();
    for (PhotoInfo photo : photos) {
        /*
        Ensure that this photo is persistence & the instance belongs to 
        current persistence context
         */
        changedPhotos.add(photo);
        VersionedObjectEditor<PhotoInfo> pe = new VersionedObjectEditor(photo, resolverFactory);
        PhotoEditor pep = (PhotoEditor) pe.getProxy();
        RawSettingsFactory rawSettingsFactory = null;
        ChannelMapOperationFactory channelMapFactory = null;

        // New processing operations
        ImageOpChain procChain = photo.getProcessing();
        ProcGraphEditorHelper rawConvHelper = null;
        ProcGraphEditorHelper rawMapHelper = null;
        ProcGraphEditorHelper chanMapHelper = null;
        ProcGraphEditorHelper cropHelper = null;

        try {
            rawConvHelper = new ProcGraphEditorHelper(pe, "dcraw", DCRawOp.class);
            rawMapHelper = new ProcGraphEditorHelper(pe, "raw-map", DCRawMapOp.class);
            chanMapHelper = new ProcGraphEditorHelper(pe, "chan-map", ChanMapOp.class);
            cropHelper = new ProcGraphEditorHelper(pe, "crop", CropOp.class);
        } catch (IllegalAccessException ex) {
            // Should not happen
            log.error(ex);
            throw new CommandException("Unexpected problem instantiating processing grap helpers", ex);
        } catch (InstantiationException ex) {
            // Should not happen
            log.error(ex);
            throw new CommandException("Unexpected problem instantiating processing grap helpers", ex);
        }

        for (Map.Entry<String, SetChange> e : modifiedSets.entrySet()) {
            for (Object val : e.getValue().added) {
                pe.addToSet(e.getKey(), val);
            }
            for (Object val : e.getValue().removed) {
                pe.removeFromSet(e.getKey(), val);
            }
        }

        for (Map.Entry<String, Object> e : changedFields.entrySet()) {
            String fieldName = e.getKey();
            PhotoInfoFields field = PhotoInfoFields.getByName(fieldName);
            Object value = e.getValue();
            try {
                if (rawSettingsFields.contains(field)) {
                    this.setRawField(rawConvHelper, rawMapHelper, field, value);
                } else if (colorCurveFields.contains(field)) {
                    setColorMapField(chanMapHelper, field, value);
                } else if (field == PhotoInfoFields.CROP_BOUNDS) {
                    Rectangle2D cropRect = (Rectangle2D) e.getValue();
                    cropHelper.setProperty("minX", cropRect.getMinX());
                    cropHelper.setProperty("maxX", cropRect.getMaxX());
                    cropHelper.setProperty("minY", cropRect.getMinY());
                    cropHelper.setProperty("maxY", cropRect.getMaxY());
                } else if (field == PhotoInfoFields.PREF_ROTATION) {
                    Double rot = (Double) e.getValue();
                    cropHelper.setProperty("rot", rot);
                } else {
                    pe.setField(fieldName, e.getValue());
                }
            } catch (IllegalAccessException ex) {
                log.error("exception while setting field " + field, ex);
                throw new CommandException("Illegal access while setting field " + field, ex);
            } catch (InvocationTargetException ex) {
                log.error("exception while setting field " + field, ex);
                throw new CommandException("Invocation target exception while setting field " + field, ex);
            } catch (NoSuchMethodException ex) {
                log.error("exception while setting field " + field, ex);
                throw new CommandException("Non-existing method called while setting field " + field, ex);
            }
        }

        ProcGraphEditorHelper[] chain = new ProcGraphEditorHelper[] { rawConvHelper, rawMapHelper,
                chanMapHelper, cropHelper };

        String nextNodeInput = null;
        for (int n = chain.length - 1; n >= 0; n--) {
            String sourcePort = null;
            // Find the node that should be connected to input of current node
            for (int m = n - 1; m >= 0; m--) {
                if (chain[m].isNodeAlreadyPresent()) {
                    sourcePort = chain[m].getNodeName() + ".out";
                    break;
                }
            }
            ProcGraphEditorHelper node = chain[n];
            if (node.isNodeAlreadyPresent() || node.addNewNode(sourcePort, nextNodeInput)) {
                nextNodeInput = node.getNodeName() + ".in";
            }
        }

        PhotoFolderDAO folderDAO = daoFactory.getPhotoFolderDAO();
        FolderPhotoAssocDAO assocDAO = daoFactory.getFolderPhotoAssocDAO();
        Set<PhotoFolder> af = new HashSet<PhotoFolder>();
        for (UUID folderId : addedToFolders) {
            log.debug("Adding photo " + photo.getUuid() + " to folder " + folderId);
            PhotoFolder folder = folderDAO.findById(folderId, false);
            VersionedObjectEditor<PhotoFolder> fe = new VersionedObjectEditor<PhotoFolder>(folder,
                    resolverFactory);
            FolderEditor fep = (FolderEditor) fe.getProxy();
            FolderPhotoAssociation a = assocDAO.getAssociation(folder, photo);
            pep.addFolderAssociation(a);
            fep.addPhotoAssociation(a);
            Change<PhotoFolder> ch = fe.apply();
            changes.add(new ChangeDTO<PhotoFolder>(ch));
            af.add(folder);
        }
        Set<PhotoFolder> rf = new HashSet<PhotoFolder>();
        Set<FolderPhotoAssociation> deletedAssocs = new HashSet<FolderPhotoAssociation>();
        for (UUID folderId : removedFromFolders) {
            log.debug("Removing photo " + photo.getUuid() + " from folder " + folderId);
            PhotoFolder folder = folderDAO.findById(folderId, false);
            VersionedObjectEditor<PhotoFolder> fe = new VersionedObjectEditor<PhotoFolder>(folder,
                    resolverFactory);
            FolderEditor fep = (FolderEditor) fe.getProxy();
            FolderPhotoAssociation a = assocDAO.getAssociation(folder, photo);
            fep.removePhotoAssociation(a);
            pep.removeFolderAssociation(a);
            deletedAssocs.add(a);
            Change<PhotoFolder> ch = fe.apply();
            changes.add(new ChangeDTO<PhotoFolder>(ch));
        }
        Change<PhotoInfo> ch = pe.apply();
        changes.add(new ChangeDTO<PhotoInfo>(ch));
        for (FolderPhotoAssociation a : deletedAssocs) {
            assocDAO.makeTransient(a);
        }
    }
}

From source file:org.photovault.imginfo.XMPConverter.java

/**
 Create XMP metadata based on given photo and image file
 @param f The image file, used to initialize media management information
 @param p The photo used to initialize descriptive fields
 @return An XMP metadata object initialized based on the given information
 @throws com.adobe.xmp.XMPException If an error occurs while creating the 
 metadata//from   www  .j av  a  2  s  . com
 */
public XMPMeta getXMPMetadata(ImageFile f, PhotoInfo p) throws XMPException {
    XMPMeta meta = XMPMetaFactory.create();
    XMPSchemaRegistry reg = XMPMetaFactory.getSchemaRegistry();

    // Check for Photovault schemas
    if (reg.getNamespacePrefix(NS_PV) == null) {
        try {
            reg.registerNamespace(NS_PV, "pv");
        } catch (XMPException e) {
            log.error("CMPException: " + e.getMessage());
        }
    }

    if (reg.getNamespacePrefix(NS_PHOTOSHOP) == null) {
        try {
            reg.registerNamespace(NS_PHOTOSHOP, "photoshop");
        } catch (XMPException e) {
            log.error("CMPException: " + e.getMessage());
        }

    }

    byte[] data = null;
    try {
        URI ifileURI = new URI("uuid", f.getId().toString(), null);
        meta.setProperty(NS_MM, "InstanceID", ifileURI.toString());
        meta.setProperty(NS_MM, "Manager", "Photovault 0.5.0dev");
        meta.setProperty(NS_MM, "ManageTo", ifileURI.toString());
    } catch (URISyntaxException ex) {
        log.error(ex);
    }
    CopyImageDescriptor firstImage = (CopyImageDescriptor) f.getImage("image#0");
    OriginalImageDescriptor orig = firstImage.getOriginal();
    String rrNS = reg.getNamespaceURI("stRef");
    try {
        URI origURI = new URI("uuid", orig.getFile().getId().toString(), orig.getLocator());
        meta.setStructField(NS_MM, "DerivedFrom", rrNS, "InstanceID", origURI.toString());
    } catch (URISyntaxException ex) {
        log.error(ex);
    }
    meta.setStructField(NS_MM, "DerivedFrom", NS_PV, "Rotation", Double.toString(firstImage.getRotation()));
    Rectangle2D cropArea = firstImage.getCropArea();
    meta.setStructField(NS_MM, "DerivedFrom", NS_PV, "XMin", Double.toString(cropArea.getMinX()));
    meta.setStructField(NS_MM, "DerivedFrom", NS_PV, "XMax", Double.toString(cropArea.getMaxX()));
    meta.setStructField(NS_MM, "DerivedFrom", NS_PV, "YMin", Double.toString(cropArea.getMinY()));
    meta.setStructField(NS_MM, "DerivedFrom", NS_PV, "YMax", Double.toString(cropArea.getMaxY()));
    ChannelMapOperation cm = firstImage.getColorChannelMapping();
    if (cm != null) {
        try {
            ByteArrayOutputStream cms = new ByteArrayOutputStream();
            ObjectOutputStream cmos = new ObjectOutputStream(cms);
            cmos.writeObject(cm);
            String cmBase64 = Base64.encodeBytes(cms.toByteArray(), Base64.GZIP | Base64.DONT_BREAK_LINES);
            meta.setStructField(NS_MM, "DerivedFrom", NS_PV, "ChannelMap", cmBase64);
        } catch (IOException e) {
            log.error("Error serializing channel map", e);
        }
    }
    RawConversionSettings rs = firstImage.getRawSettings();
    if (rs != null) {
        try {
            ByteArrayOutputStream rss = new ByteArrayOutputStream();
            ObjectOutputStream rsos = new ObjectOutputStream(rss);
            rsos.writeObject(rs);
            String rsBase64 = Base64.encodeBytes(rss.toByteArray(), Base64.GZIP | Base64.DONT_BREAK_LINES);
            meta.setStructField(NS_MM, "DerivedFrom", NS_PV, "RawConversion", rsBase64);
        } catch (IOException e) {
            log.error("Error serializing raw settings", e);
        }
    }

    /*
    Set the image metadata based the photo we are creating this copy.
    There may be other photos associated with the origial image file,
    so we should store information about these in some proprietary part 
    of metadata.
     */
    meta.appendArrayItem(NS_DC, "creator", new PropertyOptions().setArrayOrdered(true), p.getPhotographer(),
            null);
    meta.setProperty(NS_DC, "description", p.getDescription());

    double fstop = p.getFStop();
    if (fstop > 0.0) {
        String aperture = floatToRational(p.getFStop());
        meta.setProperty(NS_EXIF, "ApertureValue", aperture);
        meta.setProperty(NS_EXIF, "FNumber", aperture);
    }
    //        String film = photo.getFilm();

    int isoSpeed = p.getFilmSpeed();
    if (isoSpeed > 0) {
        meta.appendArrayItem(NS_EXIF, "ISOSpeedRatings", new PropertyOptions().setArrayOrdered(true),
                String.valueOf(isoSpeed), null);
    }

    double focalLength = p.getFocalLength();
    if (focalLength > 0.0) {
        meta.setProperty(NS_EXIF, "FocalLength", floatToRational(focalLength));
    }

    int quality = p.getQuality();
    meta.setPropertyDouble(NS_XMP_BASIC, "Rating", (double) quality);

    /* XMP location needs to be formal hierachical place, so we will store
     * this as a keyword.
     */
    PropertyOptions subjectOptions = new PropertyOptions(PropertyOptions.ARRAY);
    String shootingPlace = p.getShootingPlace();
    if (shootingPlace != null) {
        meta.appendArrayItem(NS_DC, "subject", subjectOptions, shootingPlace, null);
    }

    for (Tag tag : p.getTags()) {
        meta.appendArrayItem(NS_DC, "subject", subjectOptions, tag.getName(), null);
    }

    double expTime = p.getShutterSpeed();
    if (expTime > 0.0) {
        String shutterSpeed = expTimeAsRational(expTime);
        meta.setProperty(NS_EXIF, "ExposureTme", shutterSpeed);
    }
    //            photo.getTechNotes();

    Date shootDate = p.getShootTime();
    if (shootDate != null) {
        DateFormat dfmt = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
        String xmpShootDate = dfmt.format(shootDate);
        meta.setProperty(NS_XMP_BASIC, "CreateDate", xmpShootDate);
        meta.setProperty(NS_PHOTOSHOP, "DateCreated", xmpShootDate);
    }

    // Save technical data
    meta.setProperty(NS_TIFF, "Model", p.getCamera());
    meta.setProperty(NS_EXIF_AUX, "Lens", p.getLens());
    // TODO: add other photo attributes as well

    // Add names of the folders the photo belongs to as keywords
    for (PhotoFolder folder : p.getFolders()) {
        if (folder.getExternalDir() == null) {
            meta.appendArrayItem(NS_DC, "subject", subjectOptions, folder.getName(), null);
        }
    }

    // Save the history of the image
    ObjectHistory<PhotoInfo> h = p.getHistory();
    ObjectHistoryDTO<PhotoInfo> hdto = new ObjectHistoryDTO<PhotoInfo>(h);
    ByteArrayOutputStream histStream = new ByteArrayOutputStream();
    try {
        ObjectOutputStream histoStream = new ObjectOutputStream(histStream);
        histoStream.writeObject(hdto);
        histoStream.flush();
        histStream.flush();
        byte histData[] = histStream.toByteArray();
        String histBase64 = Base64.encodeBytes(histData, Base64.GZIP | Base64.DONT_BREAK_LINES);
        meta.setProperty(NS_PV, "History", histBase64);
    } catch (IOException e) {
        log.warn("Error serializing history", e);
    }
    return meta;
}

From source file:org.uva.itast.blended.omr.OMRUtils.java

/**
 * draws a rectangle expressed in milimeters
 * /*  ww w.  ja  va  2s .  c om*/
 * @param pageImage
 * @param markArea
 */
public static void logFrame(PageImage pageImage, Rectangle2D markArea, Color color, String label) {
    OMRUtils.logFrame(pageImage, new PagePoint(pageImage, markArea.getMinX(), markArea.getMinY()),
            new PagePoint(pageImage, markArea.getMaxX(), markArea.getMinY()),
            new PagePoint(pageImage, markArea.getMinX(), markArea.getMaxY()),
            new PagePoint(pageImage, markArea.getMaxX(), markArea.getMaxY()), color, label);
}

From source file:org.uva.itast.blended.omr.pages.PageImage.java

/**
 * Convert box from Milimeters to Pixels relative to the PageImage in the preferred resolution
 * in case of alignment rotation the returned Rectangle is the minimum bounding box that contains
 * the original corners transformed./*  w  w w  .  j a v a2s  .  c om*/
 * @param box in milimeters related to actual page
 * @return minimum bounding box in pixels related to image representation
 */
public Rectangle toPixels(Rectangle2D box) {

    Point p1 = toPixels(box.getX(), box.getY());
    Point p2 = toPixels(box.getMaxX(), box.getMaxY());
    Rectangle bboxPx = new Rectangle(p1);
    bboxPx.add(p2);
    return bboxPx;

}