Package gov.nih.mipav.model.algorithms
Class AlgorithmSphereGeneration
java.lang.Object
java.lang.Thread
gov.nih.mipav.model.algorithms.AlgorithmBase
gov.nih.mipav.model.algorithms.AlgorithmSphereGeneration
- All Implemented Interfaces:
ActionListener,WindowListener,Runnable,EventListener
This module draws uniformly randomly positioned spheres with a specified radius.
Best reference for nearest neighbor distribution for equally sized circles is: "Nearest Neighbor Assessments of
Spatial Configurations of Circles rather Than Points" by Daniel Simberloff, Ecology, Vol. 60, No. 4, Aug. 1979,
pp. 679-685.
d = diameter
lambda = mean number per unit area
Dr. Daniel Simberloff writes:
"In any event, you are probably correct that it would be more logical to caclulate rho for the points only in
the interior, not the border region, remembering to leave out the border region when calculating area."
mean nearest neighbor value = d + (exp(lambda * PI * d**2)/sqrt(lambda)*integral from t = d*sqrt(2*lambda*PI) to
t = infinity of (1/sqrt(2*PI))*exp(-t**2/2)dt. The integral is simply the 1 - Gaussian probability integral.
E(nearest neighbor distance squared) = d**2 + 1/(lambda * PI)
variance = E(r**2) - [E(r)]**2 = d**2 + 1/(lambda * PI) - [E(r)]**2
standard error = sqrt(variance)/sqrt(N)
Get percentile from Gaussian probability integral.
If the measured mean is significantly greater than the analytical mean, the distribution is uniform or regular.
If the measured mean is signficantly less than than the analytical mean, the distribution is clumped or
aggregated.
I have derived similar mathematics for Poisson distributed spheres.
Consider a Poisson distribution of points in spheres of radius r. The probability that a sphere of radius r
about a point contains no points, given a density of points = lambda is exp(-(4/3)*lambda*PI*(r**3))
Thus, 1 - exp(-(4/3)*lambda*PI*(r**3)) is the proportion of nearest neighbor distances invalid input: '<'= r.
Differentiate this expression with respect to r to obtain as the probability density function of r,
4*lambda*PI*(r**2)*exp(-(4/3)*lambda*PI*(r**3)). Now find the probability density function for spheres
of diameter dm.
For 0 invalid input: '<' r invalid input: '<'= dm, 0
For r > dm: 4*lambda*PI*(r**2)*exp(-(4/3)*lambda*PI*(r**3)) *
(1 / ( 1 - 4*lambda*PI*integral from r = 0 to r = dm of (r**2)*exp(-(4/3)*lambda*PI*(r**3))dr)) =
4*lambda*PI*(r**2)*exp(-(4/3)*lambda*PI*(r**3)) *
(1/ ( 1 + integral from r = 0 to r = dm of exp(-(4/3)*lambda*PI*(r**3))d(-(4/3)*lambda*PI*(r**3)))) =
4*lambda*PI*(r**2)*exp(-(4/3)*lambda*PI*(r**3)) *
(1 /(1 + exp(-(4/3)*lambda*PI*(dm**3)) - 1)) =
4*lambda*PI*exp((4/3)*lambda*PI*(dm**3))*(r**2)*exp(-(4/3)*lambda*PI*(r**3))
E(r) = 4*lambda*PI*exp((4/3)*lambda*PI*(dm**3)) *
integral from r = dm to r = infinity of (r**3)*exp(-(4/3)*lambda*PI*(r**3))dr =
-exp((4/3)*lambda*PI*(dm**3)) *
integral from r = dm to r = infinity of rd(exp(-(4/3)*lambda*PI*(r**3)))
-exp((4/3)*lambda*PI*(dm**3)) *
(-dm*exp(-(4/3)*lambda*PI*(dm**3)) - intergal from r = dm to r = infinity of exp(-(4/3)*lambda*PI*(r**3))dr) =
dm + exp((4/3)*lambda*PI*(dm**3))*integral from r = dm to r = infinity of exp(-(4/3)*lambda*PI*(r**3))dr
E(r**2) = 4*lambda*PI*exp((4/3)*lambda*PI*(dm**3)) *
integral from r = dm to r = infinity of (r**4)*exp(-(4/3)*lambda*PI*(r**3))dr =
-exp((4/3)*lambda*PI*(dm**3)) *
integral from r = dm to r = infinity of (r**2)*d(exp(-(4/3)*lambda*PI*(r**3))) =
-exp((4/3)*lambda*PI*(dm**3) *
(-(dm**2)*exp(-(4/3)*lambda*PI*(dm**3))
- integral from r = dm to r = infinity of exp(-(4/3)*lambda*PI*(r**3))d(r**2)) =
dm**2 + exp((4/3)*lambda*PI*(dm**3)) *
integral from r = dm to r = infinity of 2*r*exp(-(4/3)*lambda*PI*(r**3))dr
Integration.MIDINF can be too slow for radius = 0.
The Poisson distribution becomes inaccurate at higher densities because the assumption of the Poission distribution
of rare events is violated: the mean number of points per sampling unit is not small relative to the maximum
possible number of points per sampling unit.
I have used the formula from "Nearest-neighbor distribution functions in many-body systems" by S. Torquato,
B. Lu. and J. Rubinstein, The American Physical Society Physical Review A, Volume 41, Number 4,
February 15, 1990, pp. 2059-2075.
vf = volume fraction of spheres
e = (1 + vf)/((1 - vf)**3)
f = -0.5*vf*(3 + vf)/((1 - vf)**3)
g = 0.5*vf*vf/((1 - vf)**3)
mean nearest neighbor distance = diameter * (1 + integeral)
integral = integral from x = 1 to x = infinity of
exp{-vf[8*e*(x*x*x-1) + 12*f*(x*x - 1) + 24*g*(x - 1)]}
Torquato developed more accurate equations in 1995 superseding the 1990 equations. In "Nearest-neighbor
statistics for packings of hard spheres and disks" by S. Torquato, Physical Review E, Volume 51, Number 4,
April, 1995, pp. 3170 - 3182:
vf = volume fraction of spheres
mean nearest neighbor distance = diameter * (1 + integral)
integral = integral from x = 1 to x = infinity of
exp{-vf[8*a0*(x*x*x - 1) + 12*a1*(x*x - 1) + 24*a2*(x-1)]}
For vf invalid input: '<'= 0.49, the freezing packing fraction:
a0 = (1 + vf + vf*vf - vf*vf*vf)/((1 - vf)**3)
a1 = 0.5*vf*(3*vf* vf - 4*vf - 3)/((1 - vf)**3)
a2 = 0.5*vf*vf*(2 - vf)/((1 - vf)**3)
For 0.49 invalid input: '<' vf invalid input: '<' 0.64, random close packing
gf(1) = (1 - 0.49/2)/((1 - 0.49)**3)
a0 = 1 + 4*vf*gf(1)*(0.64 - 0.49)/(0.64 - vf)
a1 = 0.5*(3*vf - 4)/(1 - vf) + 2*(1 - 3*vf)*gf(1)*(0.64 - 0.49)/(0.64 - vf)
a2 = 0.5*(2 - vf)/(1 - vf) + (2*vf - 1)*gf(1)*(0.64 - 0.49)/(0.64 - vf)
The formula derived by Asim Tewari and A. M. Gokhale is accurate at both low and high densities. The reference is
"Nearest-neighbor distances between particles of finite size in three-dimensional uniform random microstructures" by
Tewari and Gokhale, Materials Science and Engineering A, Volume 385, Issues 1-2, November, 2004, pp. 332-341.
/ = 1 + ((2**(-1/6) * (n-1)!)/(([(4/3)*PI]**-1/3) * Gamma[(3*n + 1)/3])) * ((f/f0)**((2*n)/(2*n+1)))
where is the mean nth nearest-neighbor distance, f is volume fraction, is the corresponding mean
nearest-neighbor distance for a point process, and fo is the volume fraction for the close-packed structure
(1.e. PI/sqrt(18) or about 0.74).
= ([(4/3)*PI*Nv]**-1/3) * gamma[(3*n + 1)/3] / (n - 1)! = Kn*(Nv)**-1/3
where Nv is the number of points per unit volume.
/
/ = 1 + B1 * ((f/f0)**2/3)
where B1 = ((2**-1/6)/K1) - 1
For spheres of varying radii the formula is modified to
*(Nv**(1/3)) = K1*[ 1 + B1 * (f/f0)**2/3] - (1 - exp(-cv * f))
where cv is the coefficient of variation of the sphere size distribution
The reference is "Nearest neighbor distances in uniform-random poly-dispersed microstructures" by
A. Tewari and A. M. Gokhale, Materials Science and Engineering A 396 (2005), pp. 22-27.
The equation for varying radii is good for sphere volume fractions ranging from 0.0 to 0.25.
*(Nv**(1/3)) = K1*[ 1 + B1 * (f/f0)**2/3] - (1 - exp(-cv * f)) where cv is the coefficient of variation of the sphere size distribution The reference is "Nearest neighbor distances in uniform-random poly-dispersed microstructures" by A. Tewari and A. M. Gokhale, Materials Science and Engineering A 396 (2005), pp. 22-27. The equation for varying radii is good for sphere volume fractions ranging from 0.0 to 0.25.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) class(package private) class(package private) class(package private) class(package private) class(package private) class(package private) class(package private) classNested classes/interfaces inherited from class java.lang.Thread
Thread.Builder, Thread.State, Thread.UncaughtExceptionHandler -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intstatic final intstatic final intprivate doubleprivate doubleprivate intprivate doubleprivate doubleprivate intprivate doubleprivate intprivate intprivate intprivate intstatic final intstatic final intstatic final intFields inherited from class gov.nih.mipav.model.algorithms.AlgorithmBase
destFlag, destImage, image25D, mask, maxProgressValue, minProgressValue, multiThreadingEnabled, nthreads, progress, progressModulus, progressStep, runningInSeparateThread, separable, srcImage, threadStoppedFields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY -
Constructor Summary
ConstructorsConstructorDescriptionAlgorithmSphereGeneration - default constructor.AlgorithmSphereGeneration(ModelImage srcImage, int minRadius, int maxRadius, int numSpheres, int pattern, int radiusDistribution, int initialRandomSpheres, double minimumNearestNeighborDistance, double maximumNearestNeighborDistance, double lowestForbiddenNNDistance, double highestForbiddenNNDistance, double highestRegenerationNNDistance) AlgorithmRandomSphereGeneration. -
Method Summary
Methods inherited from class gov.nih.mipav.model.algorithms.AlgorithmBase
actionPerformed, addListener, addProgressChangeListener, calculateImageSize, calculatePrincipleAxis, computeElapsedTime, computeElapsedTime, convertIntoFloat, delinkProgressToAlgorithm, delinkProgressToAlgorithmMulti, displayError, errorCleanUp, fireProgressStateChanged, fireProgressStateChanged, fireProgressStateChanged, fireProgressStateChanged, fireProgressStateChanged, generateProgressValues, getDestImage, getElapsedTime, getMask, getMaxProgressValue, getMinProgressValue, getNumberOfThreads, getProgress, getProgressChangeListener, getProgressChangeListeners, getProgressModulus, getProgressStep, getProgressValues, getSrcImage, isCompleted, isImage25D, isMultiThreadingEnabled, isRunningInSeparateThread, isThreadStopped, linkProgressToAlgorithm, linkProgressToAlgorithm, makeProgress, notifyListeners, removeListener, removeProgressChangeListener, run, setCompleted, setImage25D, setMask, setMaxProgressValue, setMinProgressValue, setMultiThreadingEnabled, setNumberOfThreads, setProgress, setProgressModulus, setProgressStep, setProgressValues, setProgressValues, setRunningInSeparateThread, setSrcImage, setStartTime, setThreadStopped, startMethod, windowActivated, windowClosed, windowClosing, windowDeactivated, windowDeiconified, windowIconified, windowOpenedMethods inherited from class java.lang.Thread
activeCount, checkAccess, clone, countStackFrames, currentThread, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, isVirtual, join, join, join, join, ofPlatform, ofVirtual, onSpinWait, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, sleep, start, startVirtualThread, stop, suspend, threadId, toString, yield
-
Field Details
-
RANDOM
public static final int RANDOM- See Also:
-
AGGREGATED
public static final int AGGREGATED- See Also:
-
REGULAR
public static final int REGULAR- See Also:
-
CONSTRAINED
public static final int CONSTRAINED- See Also:
-
CONSTANT_RADIUS
public static final int CONSTANT_RADIUS- See Also:
-
UNIFORM_RADIUS
public static final int UNIFORM_RADIUS- See Also:
-
numSpheres
private int numSpheres -
pattern
private int pattern -
minRadius
private int minRadius -
maxRadius
private int maxRadius -
radiusDistribution
private int radiusDistribution -
initialRandomSpheres
private int initialRandomSpheres -
minimumNearestNeighborDistance
private double minimumNearestNeighborDistance -
maximumNearestNeighborDistance
private double maximumNearestNeighborDistance -
lowestForbiddenNNDistance
private double lowestForbiddenNNDistance -
highestForbiddenNNDistance
private double highestForbiddenNNDistance -
highestRegenerationNNDistance
private double highestRegenerationNNDistance
-
-
Constructor Details
-
AlgorithmSphereGeneration
public AlgorithmSphereGeneration()AlgorithmSphereGeneration - default constructor. -
AlgorithmSphereGeneration
public AlgorithmSphereGeneration(ModelImage srcImage, int minRadius, int maxRadius, int numSpheres, int pattern, int radiusDistribution, int initialRandomSpheres, double minimumNearestNeighborDistance, double maximumNearestNeighborDistance, double lowestForbiddenNNDistance, double highestForbiddenNNDistance, double highestRegenerationNNDistance) AlgorithmRandomSphereGeneration.- Parameters:
numSpheres- Number of spheres to be drawnpattern- RANDOM, AGGREGATED, or REGULARinitialRandomSpheres- Used in AGGREGATED. initialRandomSpheres are drawn randomly. The rest are drawn with nearestNeighborDistance less than or equal ot maximumNearestNeighborDistance.minimumNearestNeighborDistance- Used in REGULARmaximumNearestNeighborDistance- Used in AGGREGATED and REGULARlowestForbiddenNNDistance- Used in CONSTRAINEDhighestForbiddenNNDistance- Used in CONSTRAINEDsrcImg- Blank source image in which spheres will be drawnradius- Sphere radiushighestRegeneerationNNDistance- Used in CONSTRAINED
-
-
Method Details
-
finalize
public void finalize()finalize -- Overrides:
finalizein classAlgorithmBase
-
runAlgorithm
public void runAlgorithm()Starts the program.- Specified by:
runAlgorithmin classAlgorithmBase
-