001/*
002 * Copyright (c) 2003-2010 The Regents of the University of California.
003 * All rights reserved.
004 *
005 * '$Author: welker $'
006 * '$Date: 2010-05-06 05:21:26 +0000 (Thu, 06 May 2010) $' 
007 * '$Revision: 24234 $'
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 */
029
030package org.ecoinformatics.seek.gis.grass;
031
032import ptolemy.actor.TypedAtomicActor;
033import ptolemy.actor.TypedIOPort;
034import ptolemy.data.IntToken;
035import ptolemy.data.StringToken;
036import ptolemy.data.type.BaseType;
037import ptolemy.kernel.CompositeEntity;
038import ptolemy.kernel.util.IllegalActionException;
039import ptolemy.kernel.util.NameDuplicationException;
040
041/**
042 * The purpose of this actor is to take a set of (x, y) points and return the
043 * points that define the convex hull around the input. The convex hull can be
044 * thought of as the region defined by a 'rubber band' placed around the
045 * original data set. It is a sort of smallest polygon surrounding the input.
046 * The ConvexHull routine from grass is called via JNI for this calculation.
047 * 
048 * 'pointFileName' is a tab delimited text file with x,y input points
049 * 'numSitePoint' is the number of x,y pairs in the pointFileName file
050 * 'hullFileName' is the name to be given to the hull point list file
051 * 'numHullPoint' is the number of x,y pairs in the hull file 'hullFileResult'
052 * is the output hull file name (same value as the 'hullFileName' but used as a
053 * trigger for output
054 */
055public class GISHullActor extends TypedAtomicActor {
056        // input ports
057        public TypedIOPort pointFileName = new TypedIOPort(this, "pointFileName",
058                        true, false);
059        public TypedIOPort hullFileName = new TypedIOPort(this, "hullFileName",
060                        true, false);
061        public TypedIOPort numHullPoint = new TypedIOPort(this, "numHullPoint",
062                        false, true);
063        public TypedIOPort hullFileResult = new TypedIOPort(this, "hullFileResult",
064                        false, true);
065
066        public GISHullActor(CompositeEntity container, String name)
067                        throws NameDuplicationException, IllegalActionException {
068                super(container, name);
069                pointFileName.setTypeEquals(BaseType.STRING);
070                hullFileName.setTypeEquals(BaseType.STRING);
071                numHullPoint.setTypeEquals(BaseType.INT);
072                hullFileResult.setTypeEquals(BaseType.STRING);
073        }
074
075        /**
076   *
077   */
078        public void initialize() throws IllegalActionException {
079        }
080
081        /**
082   *
083   */
084        public boolean prefire() throws IllegalActionException {
085                return super.prefire();
086        }
087
088        /**
089   *
090   */
091        public void fire() throws IllegalActionException {
092                // System.out.println("firing GISHullActor");
093                super.fire();
094
095                StringToken inputFiletToken = (StringToken) pointFileName.get(0);
096                String inputFiletNameStr = inputFiletToken.stringValue();
097
098                StringToken outputFileToken = (StringToken) hullFileName.get(0);
099                String outFileStr = outputFileToken.stringValue();
100
101                // System.out.println("calling GISHull JNI code in actorcvs");
102                HullJniGlue g = new HullJniGlue();
103                int num_HullPoint = g.GISHull(inputFiletNameStr, outFileStr);
104
105                numHullPoint.broadcast(new IntToken(num_HullPoint));
106                hullFileResult.broadcast(new StringToken(outFileStr));
107        }
108}