001    /*
002     * ResampleFilter
003     * 
004     * Copyright (c) 2002, 2003 Marco Schmidt.
005     * All rights reserved.
006     */
007    
008    package net.sourceforge.jiu.geometry;
009    
010    /**
011     * Abstract base class for filters to be used with
012     * the {@link Resample} operation.
013     * @author Marco Schmidt
014     * @since 0.10.0
015     */
016    public abstract class ResampleFilter
017    {
018            private float samplingRadius;
019    
020            /**
021             * This empty constructor sets the sampling radius to the
022             * recommended sampling radius as provided by 
023             * {@link #getRecommendedSamplingRadius()}.
024             */
025            public ResampleFilter()
026            {
027                    setSamplingRadius(getRecommendedSamplingRadius());
028            }
029    
030            /**
031             * Returns the weight of the sample at the distance given
032             * by the argument value.
033             */
034            public abstract float apply(float value);
035    
036            /**
037             * Return the name of this filter.
038             * Should avoid natural language words if possible.
039             * @return String with filter name
040             */
041            public abstract String getName();
042    
043            /**
044             * Returns a recommendation for the sampling radius to
045             * be used with this filter.
046             * This recommendation value will be the default value 
047             * for the sampling radius of objects of this class.
048             * You can modify it with a call to {@link #setSamplingRadius}.
049             * @return the recommended sampling radius to be used with this filter
050             */
051            public abstract float getRecommendedSamplingRadius();
052    
053            /**
054             * Returns the sampling radius of this object.
055             * @see #getRecommendedSamplingRadius
056             * @see #setSamplingRadius
057             */
058            public float getSamplingRadius()
059            {
060                    return samplingRadius;
061            }
062    
063            /**
064             * Sets the sampling radius to a new value.
065             * Call this method if you do not want to use the default
066             * radius as provided by {@link #getRecommendedSamplingRadius}.
067             * @param newValue new sampling radius to be used with this object
068             */
069            public void setSamplingRadius(float newValue)
070            {
071                    if (newValue <= 0.0f)
072                    {
073                            throw new IllegalArgumentException("Sampling radius must be larger than 0.0f.");
074                    }
075                    samplingRadius = newValue;
076            }
077    }