001/* 002 * Copyright (c) 2015 The Regents of the University of California. 003 * All rights reserved. 004 * 005 * '$Author: crawl $' 006 * '$Date: 2015-12-17 19:34:32 +0000 (Thu, 17 Dec 2015) $' 007 * '$Revision: 34347 $' 008 * 009 * Permission is hereby granted, without written agreement and without 010 * license or royalty fees, to use, copy, modify, and distribute this 011 * software and its documentation for any purpose, provided that the above 012 * copyright notice and the following two paragraphs appear in all copies 013 * of this software. 014 * 015 * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY 016 * FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES 017 * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF 018 * THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF 019 * SUCH DAMAGE. 020 * 021 * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, 022 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 023 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE 024 * PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF 025 * CALIFORNIA HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, 026 * ENHANCEMENTS, OR MODIFICATIONS. 027 * 028 */ 029package org.kepler.gis.actor.bbox; 030 031import org.geotools.geometry.jts.ReferencedEnvelope; 032import org.kepler.gis.data.BoundingBoxToken; 033 034import ptolemy.actor.TypedAtomicActor; 035import ptolemy.actor.TypedIOPort; 036import ptolemy.data.DoubleToken; 037import ptolemy.data.Token; 038import ptolemy.data.type.BaseType; 039import ptolemy.kernel.CompositeEntity; 040import ptolemy.kernel.util.IllegalActionException; 041import ptolemy.kernel.util.NameDuplicationException; 042import ptolemy.kernel.util.SingletonAttribute; 043 044/** Get the max and min values for a bounding box. 045 * 046 * @author Daniel Crawl 047 * @version $Id: BoundingBoxValues.java 34347 2015-12-17 19:34:32Z crawl $ 048 */ 049public class BoundingBoxValues extends TypedAtomicActor { 050 051 public BoundingBoxValues(CompositeEntity container, String name) 052 throws IllegalActionException, NameDuplicationException { 053 super(container, name); 054 055 input = new TypedIOPort(this, "input", true, false); 056 input.setTypeEquals(BoundingBoxToken.BOUNDING_BOX); 057 058 maxX = new TypedIOPort(this, "maxX", false, true); 059 maxX.setTypeEquals(BaseType.DOUBLE); 060 new SingletonAttribute(maxX, "_showName"); 061 062 maxY = new TypedIOPort(this, "maxY", false, true); 063 maxY.setTypeEquals(BaseType.DOUBLE); 064 new SingletonAttribute(maxY, "_showName"); 065 066 minX = new TypedIOPort(this, "minX", false, true); 067 minX.setTypeEquals(BaseType.DOUBLE); 068 new SingletonAttribute(minX, "_showName"); 069 070 minY = new TypedIOPort(this, "minY", false, true); 071 minY.setTypeEquals(BaseType.DOUBLE); 072 new SingletonAttribute(minY, "_showName"); 073 } 074 075 @Override 076 public void fire() throws IllegalActionException { 077 078 super.fire(); 079 080 Token token = input.get(0); 081 if(token == null) { 082 throw new IllegalActionException(this, "Must provide bounding box."); 083 } 084 085 ReferencedEnvelope envelope = ((BoundingBoxToken)token).boundingBoxValue(); 086 087 maxX.broadcast(new DoubleToken(envelope.getMaxX())); 088 maxY.broadcast(new DoubleToken(envelope.getMaxY())); 089 minX.broadcast(new DoubleToken(envelope.getMinX())); 090 minY.broadcast(new DoubleToken(envelope.getMinY())); 091 } 092 093 /** The bounding box. */ 094 public TypedIOPort input; 095 096 /** The maximum X value. */ 097 public TypedIOPort maxX; 098 099 /** The maximum Y value. */ 100 public TypedIOPort maxY; 101 102 /** The minimum X value. */ 103 public TypedIOPort minX; 104 105 /** The minimum Y value. */ 106 public TypedIOPort minY; 107}