1dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond/* 2dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * Licensed to the Apache Software Foundation (ASF) under one or more 3dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * contributor license agreements. See the NOTICE file distributed with 4dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * this work for additional information regarding copyright ownership. 5dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * The ASF licenses this file to You under the Apache License, Version 2.0 6dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * (the "License"); you may not use this file except in compliance with 7dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * the License. You may obtain a copy of the License at 8dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * 9dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * http://www.apache.org/licenses/LICENSE-2.0 10dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * 11dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * Unless required by applicable law or agreed to in writing, software 12dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * distributed under the License is distributed on an "AS IS" BASIS, 13dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * See the License for the specific language governing permissions and 15dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * limitations under the License. 16dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond */ 17dee0849a9704d532af0b550146cbafbaa6ee1d19Raymondpackage org.apache.commons.math.analysis.interpolation; 18dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond 19dee0849a9704d532af0b550146cbafbaa6ee1d19Raymondimport org.apache.commons.math.MathException; 20dee0849a9704d532af0b550146cbafbaa6ee1d19Raymondimport org.apache.commons.math.analysis.MultivariateRealFunction; 21dee0849a9704d532af0b550146cbafbaa6ee1d19Raymondimport org.apache.commons.math.exception.NotPositiveException; 22dee0849a9704d532af0b550146cbafbaa6ee1d19Raymondimport org.apache.commons.math.exception.NotStrictlyPositiveException; 23dee0849a9704d532af0b550146cbafbaa6ee1d19Raymondimport org.apache.commons.math.random.UnitSphereRandomVectorGenerator; 24dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond 25dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond/** 26dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * Interpolator that implements the algorithm described in 27dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <em>William Dudziak</em>'s 28dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <a href="http://www.dudziak.com/microsphere.pdf">MS thesis</a>. 29dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * @since 2.1 30dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * 31dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * @version $Revision: 980944 $ $Date: 2010-07-30 22:31:11 +0200 (ven. 30 juil. 2010) $ 32dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond */ 33dee0849a9704d532af0b550146cbafbaa6ee1d19Raymondpublic class MicrosphereInterpolator 34dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond implements MultivariateRealInterpolator { 35dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond 36dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond /** 37dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * Default number of surface elements that composes the microsphere. 38dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond */ 39dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond public static final int DEFAULT_MICROSPHERE_ELEMENTS = 2000; 40dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond 41dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond /** 42dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * Default exponent used the weights calculation. 43dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond */ 44dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond public static final int DEFAULT_BRIGHTNESS_EXPONENT = 2; 45dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond 46dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond /** 47dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * Number of surface elements of the microsphere. 48dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond */ 49dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond private int microsphereElements; 50dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond 51dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond /** 52dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * Exponent used in the power law that computes the weights of the 53dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * sample data. 54dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond */ 55dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond private int brightnessExponent; 56dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond 57dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond /** Create a microsphere interpolator with default settings. 58dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <p>Calling this constructor is equivalent to call {@link 59dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * #MicrosphereInterpolator(int, int) 60dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * MicrosphereInterpolator(MicrosphereInterpolator.DEFAULT_MICROSPHERE_ELEMENTS, 61dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * MicrosphereInterpolator.DEFAULT_BRIGHTNESS_EXPONENT)}.</p> 62dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond */ 63dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond public MicrosphereInterpolator() { 64dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond this(DEFAULT_MICROSPHERE_ELEMENTS, DEFAULT_BRIGHTNESS_EXPONENT); 65dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond } 66dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond 67dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond /** Create a microsphere interpolator. 68dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * @param microsphereElements number of surface elements of the microsphere. 69dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * @param brightnessExponent exponent used in the power law that computes the 70dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * weights of the sample data. 71dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * @throws NotPositiveException if {@code microsphereElements <= 0} 72dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * or {@code brightnessExponent < 0}. 73dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond */ 74dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond public MicrosphereInterpolator(final int microsphereElements, 75dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond final int brightnessExponent) { 76dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond setMicropshereElements(microsphereElements); 77dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond setBrightnessExponent(brightnessExponent); 78dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond } 79dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond 80dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond /** 81dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * {@inheritDoc} 82dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond */ 83dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond public MultivariateRealFunction interpolate(final double[][] xval, 84dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond final double[] yval) 85dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond throws MathException, IllegalArgumentException { 86dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond final UnitSphereRandomVectorGenerator rand 87dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond = new UnitSphereRandomVectorGenerator(xval[0].length); 88dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond return new MicrosphereInterpolatingFunction(xval, yval, 89dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond brightnessExponent, 90dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond microsphereElements, 91dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond rand); 92dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond } 93dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond 94dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond /** 95dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * Set the brightness exponent. 96dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * @param exponent Exponent for computing the distance dimming 97dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * factor. 98dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * @throws NotPositiveException if {@code exponent < 0}. 99dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond */ 100dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond public void setBrightnessExponent(final int exponent) { 101dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond if (exponent < 0) { 102dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond throw new NotPositiveException(exponent); 103dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond } 104dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond brightnessExponent = exponent; 105dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond } 106dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond 107dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond /** 108dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * Set the number of microsphere elements. 109dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * @param elements Number of surface elements of the microsphere. 110dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * @throws NotStrictlyPositiveException if {@code elements <= 0}. 111dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond */ 112dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond public void setMicropshereElements(final int elements) { 113dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond if (elements <= 0) { 114dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond throw new NotStrictlyPositiveException(elements); 115dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond } 116dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond microsphereElements = elements; 117dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond } 118dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond} 119