use of gnu.trove.list.array.TLongArrayList in project GDSC-SMLM by aherbert.
the class ResultsImageSampler method createEmptySampleIndices.
private void createEmptySampleIndices() {
// Create the empty blocks
long total = stack.getSize() * xy_blocks;
long empty = total - data.length;
if (empty == 0) {
// All indices are used
no = new long[0];
} else {
// Sort by index
Arrays.sort(data, ic);
// Randomly sample indices that are not used.
if (maxNumberOfEmptySamples > 0) {
// Just enumerate the first N. Since they are empty it should not matter
// unless the noise characteristics change over the image duration.
long emptyCandidate = 0;
long[] list = new long[(int) Math.min(empty, maxNumberOfEmptySamples)];
int c = 0;
OUTER: for (int i = 0; i < data.length; i++) {
long current = data[i].index;
// If the current index is bigger than the candidate then it must be empty
while (current > emptyCandidate) {
// Add all those that are empty
list[c++] = emptyCandidate++;
if (c == list.length)
break OUTER;
}
// Set the next candidate
emptyCandidate = current + 1;
}
no = Arrays.copyOf(list, c);
} else {
// Sample throughout the localisation time course
TLongArrayList list = new TLongArrayList(data.length);
if (empty < data.length) {
// We can pick all the indices that are missing
long emptyCandidate = 0;
for (int i = 0; i < data.length; i++) {
long current = data[i].index;
// If the current index is bigger than the candidate then it must be empty
while (current > emptyCandidate) {
// Add all those that are empty
list.add(emptyCandidate++);
}
// Set the next candidate
emptyCandidate = current + 1;
}
} else {
// There are many empty blocks so just sample blocks
// after those with localisations.
long emptyCandidate = 1;
for (int i = 0; i < data.length; i++) {
long current = data[i].index;
// If the current index is bigger than the candidate then it must be empty
if (current > emptyCandidate) {
// Note: we only sample the next empty index after an index with data
// This means the number of frames could be lower
list.add(emptyCandidate);
}
// Set the next candidate
emptyCandidate = current + 1;
}
}
no = list.toArray();
}
}
}
use of gnu.trove.list.array.TLongArrayList in project OsmAnd-tools by osmandapp.
the class IndexRouteCreator method writeBinaryMapBlock.
public static void writeBinaryMapBlock(rtree.Node parent, Rect parentBounds, RTree r, BinaryMapIndexWriter writer, RouteWriteContext wc, boolean basemap) throws IOException, RTreeException, SQLException {
Element[] e = parent.getAllElements();
RouteDataBlock.Builder dataBlock = null;
BinaryFileReference ref = wc.treeHeader.get(parent.getNodeIndex());
wc.wayMapIds.clear();
wc.wayMapIdsCache.clear();
wc.pointMapIds.clear();
for (int i = 0; i < parent.getTotalElements(); i++) {
if (e[i].getElementType() == rtree.Node.LEAF_NODE) {
long id = e[i].getPtr();
// IndexRouteCreator.SELECT_STAT;
// "SELECT types, pointTypes, pointIds, pointCoordinates, name FROM route_objects WHERE id = ?"
boolean retrieveObject = wc.retrieveObject(id);
if (retrieveObject) {
if (dataBlock == null) {
dataBlock = RouteDataBlock.newBuilder();
wc.stringTable.clear();
wc.wayMapIds.clear();
wc.wayMapIdsCache.clear();
wc.pointMapIds.clear();
}
int cid = wc.registerWayMapId(id);
TLongArrayList restrictions = wc.highwayRestrictions.get(id);
if (!basemap && restrictions != null) {
for (int li = 0; li < restrictions.size(); li++) {
Builder restriction = RestrictionData.newBuilder();
restriction.setFrom(cid);
int toId = wc.registerWayMapId(restrictions.get(li) >> 3);
restriction.setTo(toId);
restriction.setType((int) (restrictions.get(li) & 0x7));
dataBlock.addRestrictions(restriction.build());
}
}
RouteData routeData = writer.writeRouteData(cid, parentBounds.getMinX(), parentBounds.getMinY(), wc.wayTypes, wc.points.toArray(new RoutePointToWrite[wc.points.size()]), wc.wayNames, wc.stringTable, wc.pointNames, dataBlock, true, false);
if (routeData != null) {
dataBlock.addDataObjects(routeData);
}
} else {
if (wc.logMapDataWarn != null) {
// $NON-NLS-1$
wc.logMapDataWarn.error("Something goes wrong with id = " + id);
} else {
System.err.println("Something goes wrong with id = " + id);
}
}
}
}
if (dataBlock != null) {
IdTable.Builder idTable = IdTable.newBuilder();
long prev = 0;
for (int i = 0; i < wc.wayMapIds.size(); i++) {
idTable.addRouteId(wc.wayMapIds.getQuick(i) - prev);
prev = wc.wayMapIds.getQuick(i);
}
// if (WRITE_POINT_ID) {
// prev = 0;
// for (int i = 0; i < pointMapIds.size(); i++) {
// prev = pointMapIds.getQuick(i);
// }
// }
dataBlock.setIdTable(idTable.build());
writer.writeRouteDataBlock(dataBlock, wc.stringTable, ref);
}
for (int i = 0; i < parent.getTotalElements(); i++) {
if (e[i].getElementType() != rtree.Node.LEAF_NODE) {
long ptr = e[i].getPtr();
rtree.Node ns = r.getReadNode(ptr);
writeBinaryMapBlock(ns, e[i].getRect(), r, writer, wc, basemap);
}
}
}
use of gnu.trove.list.array.TLongArrayList in project OsmAnd-tools by osmandapp.
the class ManyToOneRoadCalculation method convertToRoadIds.
private TLongArrayList convertToRoadIds(ManyToManySegment fnsResult, float distanceFromStart) {
TLongArrayList set = new TLongArrayList();
ManyToManySegment ms = fnsResult;
while (ms != null) {
set.add(ms.road.id);
ms = ms.parentSegment;
if (ms.distanceFromStart < distanceFromStart) {
break;
}
}
return set;
}
use of gnu.trove.list.array.TLongArrayList in project OsmAnd-tools by osmandapp.
the class ManyToOneRoadCalculation method combineWithLocal.
private void combineWithLocal(List<TLongArrayList> sets, TLongArrayList source) {
boolean found = false;
TLongHashSet set = new TLongHashSet(source);
for (TLongArrayList oneList : sets) {
int k = 0;
for (; k < oneList.size(); k++) {
if (set.contains(oneList.get(k))) {
break;
}
}
if (k < oneList.size()) {
oneList.remove(0, k);
for (k = 0; k < oneList.size(); k++) {
if (!set.contains(oneList.get(k))) {
break;
}
}
if (k < oneList.size()) {
oneList.remove(k, oneList.size() - k);
}
found = true;
}
if (found) {
break;
}
}
if (!found) {
sets.add(source);
}
}
use of gnu.trove.list.array.TLongArrayList in project OsmAnd-tools by osmandapp.
the class OsmStorageWriter method writeOSM.
public void writeOSM(OutputStream output, Map<EntityId, EntityInfo> entityInfo, Collection<Node> nodes, Collection<Way> ways, Collection<Relation> relations, boolean skipMissingMembers) throws FactoryConfigurationError, XMLStreamException {
// transformer.setOutputProperty(OutputKeys.INDENT, "yes");
// String indent = "{http://xml.apache.org/xslt}indent-amount";
// transformer.setOutputProperty(indent, "4");
XMLOutputFactory xof = XMLOutputFactory.newInstance();
XMLStreamWriter streamWriter = xof.createXMLStreamWriter(new OutputStreamWriter(output));
streamWriter.writeStartDocument();
Set<EntityId> nd = new HashSet<Entity.EntityId>();
writeStartElement(streamWriter, ELEM_OSM, "");
streamWriter.writeAttribute(ATTR_VERSION, "0.6");
for (Node n : nodes) {
writeStartElement(streamWriter, ELEM_NODE, INDENT);
streamWriter.writeAttribute(ATTR_LAT, String.valueOf(n.getLatitude()));
streamWriter.writeAttribute(ATTR_LON, String.valueOf(n.getLongitude()));
streamWriter.writeAttribute(ATTR_ID, String.valueOf(n.getId()));
writeEntityAttributes(streamWriter, n, entityInfo.get(EntityId.valueOf(n)));
writeTags(streamWriter, n);
writeEndElement(streamWriter, INDENT);
if (skipMissingMembers) {
nd.add(EntityId.valueOf(n));
}
}
for (Way w : ways) {
writeStartElement(streamWriter, ELEM_WAY, INDENT);
streamWriter.writeAttribute(ATTR_ID, String.valueOf(w.getId()));
writeEntityAttributes(streamWriter, w, entityInfo.get(EntityId.valueOf(w)));
TLongArrayList ids = w.getNodeIds();
for (int i = 0; i < ids.size(); i++) {
writeStartElement(streamWriter, ELEM_ND, INDENT2);
streamWriter.writeAttribute(ATTR_REF, String.valueOf(ids.get(i)));
writeEndElement(streamWriter, INDENT2);
}
writeTags(streamWriter, w);
writeEndElement(streamWriter, INDENT);
if (skipMissingMembers) {
nd.add(EntityId.valueOf(w));
}
}
for (Relation r : relations) {
if (skipMissingMembers) {
nd.add(EntityId.valueOf(r));
}
writeStartElement(streamWriter, ELEM_RELATION, INDENT);
streamWriter.writeAttribute(ATTR_ID, String.valueOf(r.getId()));
writeEntityAttributes(streamWriter, r, entityInfo.get(EntityId.valueOf(r)));
for (RelationMember e : r.getMembers()) {
if (skipMissingMembers && !nd.contains(e.getEntityId())) {
continue;
}
writeStartElement(streamWriter, ELEM_MEMBER, INDENT2);
streamWriter.writeAttribute(ATTR_REF, String.valueOf(e.getEntityId().getId()));
String s = e.getRole();
if (s == null) {
s = "";
}
streamWriter.writeAttribute(ATTR_ROLE, s);
streamWriter.writeAttribute(ATTR_TYPE, e.getEntityId().getType().toString().toLowerCase());
writeEndElement(streamWriter, INDENT2);
}
writeTags(streamWriter, r);
writeEndElement(streamWriter, INDENT);
}
// osm
writeEndElement(streamWriter, "");
streamWriter.writeEndDocument();
streamWriter.flush();
}
Aggregations