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 agents.anac.y2019.harddealer.math3.analysis.interpolation;
|
---|
18 |
|
---|
19 | import agents.anac.y2019.harddealer.math3.util.FastMath;
|
---|
20 | import agents.anac.y2019.harddealer.math3.util.MathUtils;
|
---|
21 |
|
---|
22 | /**
|
---|
23 | * Utility class for the {@link MicrosphereProjectionInterpolator} algorithm.
|
---|
24 | * For 2D interpolation, this class constructs the microsphere as a series of
|
---|
25 | * evenly spaced facets (rather than generating random normals as in the
|
---|
26 | * base implementation).
|
---|
27 | *
|
---|
28 | * @since 3.6
|
---|
29 | */
|
---|
30 | public class InterpolatingMicrosphere2D extends InterpolatingMicrosphere {
|
---|
31 | /** Space dimension. */
|
---|
32 | private static final int DIMENSION = 2;
|
---|
33 |
|
---|
34 | /**
|
---|
35 | * Create a sphere from vectors regularly sampled around a circle.
|
---|
36 | *
|
---|
37 | * @param size Number of surface elements of the sphere.
|
---|
38 | * @param maxDarkFraction Maximum fraction of the facets that can be dark.
|
---|
39 | * If the fraction of "non-illuminated" facets is larger, no estimation
|
---|
40 | * of the value will be performed, and the {@code background} value will
|
---|
41 | * be returned instead.
|
---|
42 | * @param darkThreshold Value of the illumination below which a facet is
|
---|
43 | * considered dark.
|
---|
44 | * @param background Value returned when the {@code maxDarkFraction}
|
---|
45 | * threshold is exceeded.
|
---|
46 | * @throws agents.anac.y2019.harddealer.math3.exception.NotStrictlyPositiveException
|
---|
47 | * if {@code size <= 0}.
|
---|
48 | * @throws agents.anac.y2019.harddealer.math3.exception.NotPositiveException if
|
---|
49 | * {@code darkThreshold < 0}.
|
---|
50 | * @throws agents.anac.y2019.harddealer.math3.exception.OutOfRangeException if
|
---|
51 | * {@code maxDarkFraction} does not belong to the interval {@code [0, 1]}.
|
---|
52 | */
|
---|
53 | public InterpolatingMicrosphere2D(int size,
|
---|
54 | double maxDarkFraction,
|
---|
55 | double darkThreshold,
|
---|
56 | double background) {
|
---|
57 | super(DIMENSION, size, maxDarkFraction, darkThreshold, background);
|
---|
58 |
|
---|
59 | // Generate the microsphere normals.
|
---|
60 | for (int i = 0; i < size; i++) {
|
---|
61 | final double angle = i * MathUtils.TWO_PI / size;
|
---|
62 |
|
---|
63 | add(new double[] { FastMath.cos(angle),
|
---|
64 | FastMath.sin(angle) },
|
---|
65 | false);
|
---|
66 | }
|
---|
67 | }
|
---|
68 |
|
---|
69 | /**
|
---|
70 | * Copy constructor.
|
---|
71 | *
|
---|
72 | * @param other Instance to copy.
|
---|
73 | */
|
---|
74 | protected InterpolatingMicrosphere2D(InterpolatingMicrosphere2D other) {
|
---|
75 | super(other);
|
---|
76 | }
|
---|
77 |
|
---|
78 | /**
|
---|
79 | * Perform a copy.
|
---|
80 | *
|
---|
81 | * @return a copy of this instance.
|
---|
82 | */
|
---|
83 | @Override
|
---|
84 | public InterpolatingMicrosphere2D copy() {
|
---|
85 | return new InterpolatingMicrosphere2D(this);
|
---|
86 | }
|
---|
87 | }
|
---|