-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
38 additions
and
0 deletions.
There are no files selected for viewing
38 changes: 38 additions & 0 deletions
38
render-app/src/main/java/org/janelia/alignment/inpainting/RandomDirection3D.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package org.janelia.alignment.inpainting; | ||
|
||
import java.util.Random; | ||
|
||
/** | ||
* A statistic that yields a completely random 3D direction for each sample. | ||
*/ | ||
public class RandomDirection3D implements DirectionalStatistic { | ||
|
||
private final Random random; | ||
|
||
/** | ||
* Creates a new statistic with a random seed. | ||
*/ | ||
public RandomDirection3D() { | ||
this(new Random()); | ||
} | ||
|
||
/** | ||
* Creates a new statistic with the given random number generator. | ||
* | ||
* @param random the random number generator to use | ||
*/ | ||
public RandomDirection3D(final Random random) { | ||
this.random = random; | ||
} | ||
|
||
@Override | ||
public void sample(final double[] direction) { | ||
final double x = random.nextGaussian(); | ||
final double y = random.nextGaussian(); | ||
final double z = random.nextGaussian(); | ||
final double norm = Math.sqrt(x * x + y * y + z * z); | ||
direction[0] = x / norm; | ||
direction[1] = y / norm; | ||
direction[2] = z / norm; | ||
} | ||
} |