InterpolatingMicrosphere2D.java

  1. /*
  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.  */
  17. package org.apache.commons.math4.legacy.analysis.interpolation;

  18. import org.apache.commons.math4.core.jdkmath.JdkMath;

  19. /**
  20.  * Utility class for the {@link MicrosphereProjectionInterpolator} algorithm.
  21.  * For 2D interpolation, this class constructs the microsphere as a series of
  22.  * evenly spaced facets (rather than generating random normals as in the
  23.  * base implementation).
  24.  *
  25.  * @since 4.0
  26.  */
  27. public class InterpolatingMicrosphere2D extends InterpolatingMicrosphere {
  28.     /** Space dimension. */
  29.     private static final int DIMENSION = 2;

  30.     /**
  31.      * Create a sphere from vectors regularly sampled around a circle.
  32.      *
  33.      * @param size Number of surface elements of the sphere.
  34.      * @param maxDarkFraction Maximum fraction of the facets that can be dark.
  35.      * If the fraction of "non-illuminated" facets is larger, no estimation
  36.      * of the value will be performed, and the {@code background} value will
  37.      * be returned instead.
  38.      * @param darkThreshold Value of the illumination below which a facet is
  39.      * considered dark.
  40.      * @param background Value returned when the {@code maxDarkFraction}
  41.      * threshold is exceeded.
  42.      * @throws org.apache.commons.math4.legacy.exception.NotStrictlyPositiveException
  43.      * if {@code size <= 0}.
  44.      * @throws org.apache.commons.math4.legacy.exception.NotPositiveException if
  45.      * {@code darkThreshold < 0}.
  46.      * @throws org.apache.commons.math4.legacy.exception.OutOfRangeException if
  47.      * {@code maxDarkFraction} does not belong to the interval {@code [0, 1]}.
  48.      */
  49.     public InterpolatingMicrosphere2D(int size,
  50.                                       double maxDarkFraction,
  51.                                       double darkThreshold,
  52.                                       double background) {
  53.         super(DIMENSION, size, maxDarkFraction, darkThreshold, background);

  54.         // Generate the microsphere normals.
  55.         final double twopi = 2 * Math.PI;
  56.         for (int i = 0; i < size; i++) {
  57.             final double angle = i * twopi / size;

  58.             add(new double[] { JdkMath.cos(angle),
  59.                                JdkMath.sin(angle) },
  60.                 false);
  61.         }
  62.     }

  63.     /**
  64.      * Copy constructor.
  65.      *
  66.      * @param other Instance to copy.
  67.      */
  68.     protected InterpolatingMicrosphere2D(InterpolatingMicrosphere2D other) {
  69.         super(other);
  70.     }

  71.     /**
  72.      * Perform a copy.
  73.      *
  74.      * @return a copy of this instance.
  75.      */
  76.     @Override
  77.     public InterpolatingMicrosphere2D copy() {
  78.         return new InterpolatingMicrosphere2D(this);
  79.     }
  80. }