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