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.  *      https://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. /*
  18.  * This is not the original file distributed by the Apache Software Foundation
  19.  * It has been modified by the Hipparchus project
  20.  */
  21. package org.hipparchus.analysis.interpolation;

  22. import org.hipparchus.util.FastMath;
  23. import org.hipparchus.util.MathUtils;
  24. import org.hipparchus.util.SinCos;

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

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

  59.         // Generate the microsphere normals.
  60.         for (int i = 0; i < size; i++) {
  61.             final double angle   = i * MathUtils.TWO_PI / size;
  62.             final SinCos scAngle = FastMath.sinCos(angle);

  63.             add(new double[] { scAngle.cos(),
  64.                                scAngle.sin() },
  65.                 false);
  66.         }
  67.     }

  68.     /**
  69.      * Copy constructor.
  70.      *
  71.      * @param other Instance to copy.
  72.      */
  73.     protected InterpolatingMicrosphere2D(InterpolatingMicrosphere2D other) {
  74.         super(other);
  75.     }

  76.     /**
  77.      * Perform a copy.
  78.      *
  79.      * @return a copy of this instance.
  80.      */
  81.     @Override
  82.     public InterpolatingMicrosphere2D copy() {
  83.         return new InterpolatingMicrosphere2D(this);
  84.     }
  85. }