use of gnu.trove.set.hash.TIntHashSet in project MinecraftForge by MinecraftForge.
the class PotionRegistryDebug method preInit.
@Mod.EventHandler
public void preInit(FMLPreInitializationEvent event) {
// test automatic id distribution
Potion forge = new PotionForge(new ResourceLocation(ForgeVersion.MOD_ID, "forge"), false, 0xff00ff);
// test that ids above 127 work
Potion forgy = new PotionForge(new ResourceLocation(ForgeVersion.MOD_ID, "forgy"), true, 0x00ff00);
//TODo: Generic this out in GameRegistry, 'RegistryEntry' base type?
GameData.getPotionRegistry().register(-1, new ResourceLocation(ForgeVersion.MOD_ID, "forge"), forge);
GameData.getPotionRegistry().register(200, new ResourceLocation(ForgeVersion.MOD_ID, "forgy"), forgy);
Random rand = new Random();
TIntSet taken = new TIntHashSet(100);
int ra = rand.nextInt(100) + 100;
taken.add(ra);
for (int i = 0; i < 20; i++) {
int r = rand.nextInt(200) + 35;
while (taken.contains(r)) r = rand.nextInt(200) + 35;
//r = 32+i;
taken.add(r);
// this potions will most likely not have the same IDs between server and client.
// The forge handshake on connect should fix this.
//new PotionForge(new ResourceLocation(ForgeModContainer.MOD_ID, "randomPotion" + r), false, 0xff00ff);
}
}
use of gnu.trove.set.hash.TIntHashSet in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.
the class SpatialDetector method calculateSpatialOccupation.
public void calculateSpatialOccupation() {
nextQueue.add(firstBlock.getY() + maxRange * maxRangeHalved + maxRangeSquared * maxRangeHalved);
MutableBlockPos inRealWorld = new MutableBlockPos();
int hash;
while (!nextQueue.isEmpty() && !cleanHouse) {
TIntIterator queueIter = nextQueue.iterator();
foundSet.addAll(nextQueue);
nextQueue = new TIntHashSet();
while (queueIter.hasNext()) {
hash = queueIter.next();
setPosWithRespectTo(hash, firstBlock, inRealWorld);
if (corners) {
tryExpanding(inRealWorld.getX() - 1, inRealWorld.getY() - 1, inRealWorld.getZ() - 1, hash - maxRange - 1 - maxRangeSquared);
tryExpanding(inRealWorld.getX() - 1, inRealWorld.getY() - 1, inRealWorld.getZ(), hash - maxRange - 1);
tryExpanding(inRealWorld.getX() - 1, inRealWorld.getY() - 1, inRealWorld.getZ() + 1, hash - maxRange - 1 + maxRangeSquared);
tryExpanding(inRealWorld.getX() - 1, inRealWorld.getY(), inRealWorld.getZ() - 1, hash - maxRange - maxRangeSquared);
tryExpanding(inRealWorld.getX() - 1, inRealWorld.getY(), inRealWorld.getZ(), hash - maxRange);
tryExpanding(inRealWorld.getX() - 1, inRealWorld.getY(), inRealWorld.getZ() + 1, hash - maxRange + maxRangeSquared);
tryExpanding(inRealWorld.getX() - 1, inRealWorld.getY() + 1, inRealWorld.getZ() - 1, hash - maxRange + 1 - maxRangeSquared);
tryExpanding(inRealWorld.getX() - 1, inRealWorld.getY() + 1, inRealWorld.getZ(), hash - maxRange + 1);
tryExpanding(inRealWorld.getX() - 1, inRealWorld.getY() + 1, inRealWorld.getZ() + 1, hash - maxRange + 1 + maxRangeSquared);
tryExpanding(inRealWorld.getX(), inRealWorld.getY() - 1, inRealWorld.getZ() - 1, hash - 1 - maxRangeSquared);
tryExpanding(inRealWorld.getX(), inRealWorld.getY() - 1, inRealWorld.getZ(), hash - 1);
tryExpanding(inRealWorld.getX(), inRealWorld.getY() - 1, inRealWorld.getZ() + 1, hash - 1 + maxRangeSquared);
tryExpanding(inRealWorld.getX(), inRealWorld.getY(), inRealWorld.getZ() - 1, hash - maxRangeSquared);
tryExpanding(inRealWorld.getX(), inRealWorld.getY(), inRealWorld.getZ() + 1, hash + maxRangeSquared);
tryExpanding(inRealWorld.getX(), inRealWorld.getY() + 1, inRealWorld.getZ() - 1, hash + 1 - maxRangeSquared);
tryExpanding(inRealWorld.getX(), inRealWorld.getY() + 1, inRealWorld.getZ(), hash + 1);
tryExpanding(inRealWorld.getX(), inRealWorld.getY() + 1, inRealWorld.getZ() + 1, hash + 1 + maxRangeSquared);
tryExpanding(inRealWorld.getX() + 1, inRealWorld.getY() - 1, inRealWorld.getZ() - 1, hash + maxRange - 1 - maxRangeSquared);
tryExpanding(inRealWorld.getX() + 1, inRealWorld.getY() - 1, inRealWorld.getZ(), hash + maxRange - 1);
tryExpanding(inRealWorld.getX() + 1, inRealWorld.getY() - 1, inRealWorld.getZ() + 1, hash + maxRange - 1 + maxRangeSquared);
tryExpanding(inRealWorld.getX() + 1, inRealWorld.getY(), inRealWorld.getZ() - 1, hash + maxRange - maxRangeSquared);
tryExpanding(inRealWorld.getX() + 1, inRealWorld.getY(), inRealWorld.getZ(), hash + maxRange);
tryExpanding(inRealWorld.getX() + 1, inRealWorld.getY(), inRealWorld.getZ() + 1, hash + maxRange + maxRangeSquared);
tryExpanding(inRealWorld.getX() + 1, inRealWorld.getY() + 1, inRealWorld.getZ() - 1, hash + maxRange + 1 - maxRangeSquared);
tryExpanding(inRealWorld.getX() + 1, inRealWorld.getY() + 1, inRealWorld.getZ(), hash + maxRange + 1);
tryExpanding(inRealWorld.getX() + 1, inRealWorld.getY() + 1, inRealWorld.getZ() + 1, hash + maxRange + 1 + maxRangeSquared);
} else {
tryExpanding(inRealWorld.getX() + 1, inRealWorld.getY(), inRealWorld.getZ(), hash + maxRange);
tryExpanding(inRealWorld.getX() - 1, inRealWorld.getY(), inRealWorld.getZ(), hash - maxRange);
tryExpanding(inRealWorld.getX(), inRealWorld.getY() + 1, inRealWorld.getZ(), hash + 1);
tryExpanding(inRealWorld.getX(), inRealWorld.getY() - 1, inRealWorld.getZ(), hash - 1);
tryExpanding(inRealWorld.getX(), inRealWorld.getY(), inRealWorld.getZ() + 1, hash + maxRangeSquared);
tryExpanding(inRealWorld.getX(), inRealWorld.getY(), inRealWorld.getZ() - 1, hash - maxRangeSquared);
}
}
}
}
use of gnu.trove.set.hash.TIntHashSet in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.
the class BalloonDetector method calculateSpatialOccupation.
@Override
public void calculateSpatialOccupation() {
nextQueue.add(firstBlock.getY() + maxRange * maxRangeHalved + maxRangeSquared * maxRangeHalved);
MutableBlockPos inRealWorld = new MutableBlockPos();
int hash;
while (!nextQueue.isEmpty() && !cleanHouse) {
TIntIterator queueIter = nextQueue.iterator();
foundSet.addAll(nextQueue);
nextQueue = new TIntHashSet();
while (queueIter.hasNext()) {
hash = queueIter.next();
setPosWithRespectTo(hash, firstBlock, inRealWorld);
tryExpanding(inRealWorld.getX() + 1, inRealWorld.getY(), inRealWorld.getZ(), hash + maxRange);
tryExpanding(inRealWorld.getX() - 1, inRealWorld.getY(), inRealWorld.getZ(), hash - maxRange);
tryExpanding(inRealWorld.getX(), inRealWorld.getY() + 1, inRealWorld.getZ(), hash + 1);
// tryExpanding(inRealWorld.getX(),inRealWorld.getY()-1,inRealWorld.getZ(),hash-1);
tryExpanding(inRealWorld.getX(), inRealWorld.getY(), inRealWorld.getZ() + 1, hash + maxRangeSquared);
tryExpanding(inRealWorld.getX(), inRealWorld.getY(), inRealWorld.getZ() - 1, hash - maxRangeSquared);
}
}
}
use of gnu.trove.set.hash.TIntHashSet in project GDSC-SMLM by aherbert.
the class TraceManager method getTraces.
/**
* @return The traces that have been found using {@link #traceMolecules(double, int)}
*/
public Trace[] getTraces() {
PeakResult[] peakResults = results.toArray();
// No tracing yet performed or no thresholds
if (totalTraces == localisations.length) {
if (filterActivationFrames) {
ArrayList<Trace> traces = new ArrayList<Trace>();
for (int index = 0; index < totalTraces; index++) {
PeakResult peakResult = peakResults[localisations[index].id];
if (!outsideActivationWindow(peakResult.getFrame()))
traces.add(new Trace(peakResult));
}
return traces.toArray(new Trace[traces.size()]);
} else {
Trace[] traces = new Trace[localisations.length];
for (int index = 0; index < traces.length; index++) traces[index] = new Trace(peakResults[localisations[index].id]);
return traces;
}
}
if (tracker != null)
tracker.progress(0);
// Build the list of traces
Trace[] traces = new Trace[getTotalTraces()];
int n = 0;
//for (int index = 0; index < localisations.length; index++)
// if (localisations[index].trace == 0)
// System.out.printf("error @ %d\n", index);
// Since the trace numbers are allocated by processing the spots in frames, each frame can have
// trace number out-of-order. This occurs if re-allocation has been performed,
// e.g. [1,2,2,1,3] => [1,2,5,4,3] when spots in group 1 are reallocated before spots in group 2.
TIntHashSet processedTraces = new TIntHashSet(traces.length);
for (int index = 0; index < localisations.length; index++) {
if (tracker != null && index % 256 == 0)
tracker.progress(index, localisations.length);
final int traceId = localisations[index].trace;
if (processedTraces.contains(traceId))
continue;
processedTraces.add(traceId);
if (filterActivationFrames && outsideActivationWindow(localisations[index].t))
continue;
PeakResult peakResult = peakResults[localisations[index].id];
Trace nextTrace = new Trace(peakResult);
nextTrace.setId(traceId);
final int tLimit = maxT[traceId];
// Check if the trace has later frames
if (tLimit > localisations[index].t) {
for (int j = index + 1; j < localisations.length; j++) {
if (localisations[j].t > tLimit) {
// System.out.printf("missed %d\n", j);
break;
}
if (localisations[j].trace == traceId)
nextTrace.add(peakResults[localisations[j].id]);
}
}
//// DEBUG: Check the trace does not contain two localisations from the same time frame.
//// This should be handled by the findAlternativeForerunner code.
//int[] time = new int[nextTrace.size()];
//int count = 0;
//for (PeakResult p : nextTrace.getPoints())
//{
// for (int i = 0; i < count; i++)
// if (time[i] == p.peak)
// {
// System.out.printf("Trace %d contains multiple localisations from the same frame: %d\n", n + 1,
// p.peak);
// break;
// }
// time[count++] = p.peak;
//}
traces[n++] = nextTrace;
}
if (tracker != null)
tracker.progress(1.0);
return traces;
}
use of gnu.trove.set.hash.TIntHashSet in project GDSC-SMLM by aherbert.
the class CreateData method combineSimulationSteps.
private List<LocalisationModelSet> combineSimulationSteps(List<LocalisationModel> localisations) {
// Allow fractional integration steps
final double simulationStepsPerFrame = (settings.stepsPerSecond * settings.exposureTime) / 1000.0;
List<LocalisationModelSet> newLocalisations = new ArrayList<LocalisationModelSet>((int) (localisations.size() / simulationStepsPerFrame));
//System.out.printf("combineSimulationSteps @ %f\n", simulationStepsPerFrame);
final double gain = (settings.getTotalGain() > 0) ? settings.getTotalGain() : 1;
sortLocalisationsByIdThenTime(localisations);
int[] idList = getIds(localisations);
movingMolecules = new TIntHashSet(idList.length);
int index = 0;
for (int id : idList) {
int fromIndex = findIndexById(localisations, index, id);
if (fromIndex > -1) {
int toIndex = findLastIndexById(localisations, fromIndex, id);
List<LocalisationModel> subset = localisations.subList(fromIndex, toIndex + 1);
index = toIndex;
// Store the IDs of any moving molecules
if (isMoving(subset))
movingMolecules.add(id);
// The frames may be longer or shorter than the simulation steps. Allocate the step
// proportionately to each frame it overlaps:
//
// Steps: |-- 0 --|-- 1 --|-- 2 --|--
// Frames: |--- 0 ---|--- 1 ---|--- 2 ---|
//
// ^ ^
// | |
// | End frame
// |
// Start frame
final double firstFrame = getStartFrame(subset.get(0), simulationStepsPerFrame);
final double lastFrame = getEndFrame(subset.get(subset.size() - 1), simulationStepsPerFrame);
// Get the first frame offset and allocate space to store all potential frames
final int intFirstFrame = (int) firstFrame;
final int intLastFrame = (int) Math.ceil(lastFrame);
LocalisationModelSet[] sets = new LocalisationModelSet[intLastFrame - intFirstFrame + 1];
// Process each step
for (LocalisationModel l : subset) {
// Get the fractional start and end frames
double startFrame = getStartFrame(l, simulationStepsPerFrame);
double endFrame = getEndFrame(l, simulationStepsPerFrame);
// Round down to get the actual frames that are overlapped
int start = (int) startFrame;
int end = (int) endFrame;
// Check if the span covers a fraction of the end frame, otherwise decrement to ignore that frame
if (end > start && endFrame == end) {
// E.g. convert
// Steps: |-- 0 --|
// Frames: |- 0 -|- 1 -|- 2 -|
// to
// Steps: |-- 0 --|
// Frames: |- 0 -|- 1 -|
end--;
}
if (start == end) {
// If the step falls within one frame then add it to the set
int tIndex = start - intFirstFrame;
if (sets[tIndex] == null)
sets[tIndex] = new LocalisationModelSet(id, start);
sets[tIndex].add(l);
} else {
// Add the localisation to all the frames that the step spans
final double total = endFrame - startFrame;
//double t = 0;
for (int frame = start; frame <= end; frame++) {
// Get the fraction to allocate to this frame
double fraction;
int state = (l.isContinuous() ? LocalisationModel.CONTINUOUS : 0);
if (frame == start) {
state |= LocalisationModel.NEXT | (l.hasPrevious() ? LocalisationModel.PREVIOUS : 0);
// start
if (startFrame == start)
fraction = 1;
else
fraction = (Math.ceil(startFrame) - startFrame);
} else if (frame == end) {
state |= LocalisationModel.PREVIOUS | (l.hasNext() ? LocalisationModel.NEXT : 0);
// |=====|----|
// | |
// | endFrame
// end
fraction = (endFrame - end);
} else {
state |= LocalisationModel.CONTINUOUS;
fraction = 1;
}
//t += fraction;
// Add to the set
int tIndex = frame - intFirstFrame;
if (sets[tIndex] == null)
sets[tIndex] = new LocalisationModelSet(id, frame);
sets[tIndex].add(getFraction(l, fraction / total, state));
}
//if (t < total * 0.98)
//{
// System.out.printf("Total error %g < %g : %f (%d) -> %f (%d)\n", t, total, startFrame,
// start, endFrame, end);
//}
}
}
LocalisationModelSet previous = null;
for (int i = 0; i < sets.length; i++) {
if (sets[i] != null) {
sets[i].setPrevious(previous);
// Create a data array and store the current intensity after gain.
// This is used later to filter based on SNR
sets[i].setData(new double[] { 0, 0, 0, 0, sets[i].getIntensity() * gain });
newLocalisations.add(sets[i]);
}
previous = sets[i];
}
}
}
// Sort by time
Collections.sort(newLocalisations);
return newLocalisations;
}
Aggregations