-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add RadialKDTreeInterpolatorFactory
* and RadialKDTreeInterpolator
- Loading branch information
Showing
2 changed files
with
129 additions
and
0 deletions.
There are no files selected for viewing
82 changes: 82 additions & 0 deletions
82
...n/java/net/imglib2/algorithm/interpolation/realrandomaccess/RadialKDTreeInterpolator.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,82 @@ | ||
package net.imglib2.algorithm.interpolation.realrandomaccess; | ||
|
||
import java.util.function.DoubleUnaryOperator; | ||
|
||
import net.imglib2.KDTree; | ||
import net.imglib2.RealPoint; | ||
import net.imglib2.RealRandomAccess; | ||
import net.imglib2.interpolation.InterpolatorFactory; | ||
import net.imglib2.neighborsearch.RadiusNeighborSearch; | ||
import net.imglib2.neighborsearch.RadiusNeighborSearchOnKDTree; | ||
import net.imglib2.type.numeric.NumericType; | ||
|
||
/** | ||
* A {@link RealRandomAccess} for {@link KDTree}s using a radial function used by | ||
* {@link RadialKDTreeInterpolatorFactory}. | ||
* | ||
* @author John Bogovic | ||
*/ | ||
public class RadialKDTreeInterpolator<T extends NumericType<T>> extends RealPoint implements RealRandomAccess<T> { | ||
|
||
protected static final double minThreshold = Double.MIN_VALUE * 1000; | ||
|
||
protected final RadiusNeighborSearch<T> search; | ||
protected final double maxRadius; | ||
protected final double maxSquaredRadius; | ||
protected final KDTree<T> tree; | ||
protected final T value; | ||
protected final T tmp; | ||
protected final DoubleUnaryOperator squaredRadiusFunction; | ||
|
||
public RadialKDTreeInterpolator( | ||
final KDTree<T> tree, | ||
final DoubleUnaryOperator squaredRadiusFunction, | ||
final double maxRadius, | ||
T t) { | ||
|
||
super(tree.numDimensions()); | ||
|
||
this.squaredRadiusFunction = squaredRadiusFunction; | ||
this.tree = tree; | ||
this.search = new RadiusNeighborSearchOnKDTree<T>(tree); | ||
this.maxRadius = maxRadius; | ||
this.maxSquaredRadius = maxRadius * maxRadius; | ||
this.value = t.copy(); | ||
this.tmp = t.copy(); | ||
} | ||
|
||
public double getMaxRadius() { | ||
|
||
return maxRadius; | ||
} | ||
|
||
@Override | ||
public T get() { | ||
|
||
value.setZero(); | ||
search.search(this, maxRadius, false); | ||
if (search.numNeighbors() == 0) | ||
return value; | ||
|
||
for (int i = 0; i < search.numNeighbors(); ++i) { | ||
// can't multiply the value returned | ||
tmp.set(search.getSampler(i).get()); | ||
tmp.mul(squaredRadiusFunction.applyAsDouble(search.getSquareDistance(i))); | ||
value.add(tmp); | ||
} | ||
return value; | ||
} | ||
|
||
@Override | ||
public RadialKDTreeInterpolator<T> copy() { | ||
|
||
return new RadialKDTreeInterpolator<T>(tree, squaredRadiusFunction, maxRadius, value); | ||
} | ||
|
||
@Override | ||
public RadialKDTreeInterpolator<T> copyRealRandomAccess() { | ||
|
||
return copy(); | ||
} | ||
|
||
} |
47 changes: 47 additions & 0 deletions
47
...net/imglib2/algorithm/interpolation/realrandomaccess/RadialKDTreeInterpolatorFactory.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,47 @@ | ||
package net.imglib2.algorithm.interpolation.realrandomaccess; | ||
|
||
import java.util.function.DoubleUnaryOperator; | ||
|
||
import net.imglib2.KDTree; | ||
import net.imglib2.RealInterval; | ||
import net.imglib2.RealRandomAccess; | ||
import net.imglib2.interpolation.InterpolatorFactory; | ||
import net.imglib2.type.numeric.NumericType; | ||
|
||
/** | ||
* An {@link InterpolatorFactory} for {@link KDTree}s using a radial function. | ||
* <p> | ||
* The resulting {@link RealRandomAccess} produced by this InterpolatorFactory | ||
* returns values as a linear combination of all points within a certain radius. | ||
* The contribution of each point is weighted according to a function of its | ||
* squared radius. | ||
* | ||
* @author John Bogovic | ||
*/ | ||
public class RadialKDTreeInterpolatorFactory<T extends NumericType<T>> implements InterpolatorFactory<T, KDTree<T>> { | ||
|
||
protected final double maxRadius; | ||
protected final DoubleUnaryOperator squaredRadiusFunction; | ||
protected final T val; | ||
|
||
public RadialKDTreeInterpolatorFactory( | ||
final DoubleUnaryOperator squaredRadiusFunction, final double maxRadius, T t) { | ||
|
||
this.maxRadius = maxRadius; | ||
this.squaredRadiusFunction = squaredRadiusFunction; | ||
this.val = t; | ||
} | ||
|
||
@Override | ||
public RadialKDTreeInterpolator<T> create(final KDTree<T> tree) { | ||
|
||
return new RadialKDTreeInterpolator<T>(tree, squaredRadiusFunction, maxRadius, val); | ||
} | ||
|
||
@Override | ||
public RealRandomAccess<T> create(final KDTree<T> tree, final RealInterval interval) { | ||
|
||
return create(tree); | ||
} | ||
|
||
} |