Search in sources :

Example 1 with TLongArrayList

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();
        }
    }
}
Also used : TLongArrayList(gnu.trove.list.array.TLongArrayList)

Example 2 with TLongArrayList

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);
        }
    }
}
Also used : TLongArrayList(gnu.trove.list.array.TLongArrayList) Element(rtree.Element) LeafElement(rtree.LeafElement) Builder(net.osmand.binary.OsmandOdb.RestrictionData.Builder) RouteDataBlock(net.osmand.binary.OsmandOdb.OsmAndRoutingIndex.RouteDataBlock) IdTable(net.osmand.binary.OsmandOdb.IdTable) RoutePointToWrite(net.osmand.data.preparation.BinaryMapIndexWriter.RoutePointToWrite) RouteData(net.osmand.binary.OsmandOdb.RouteData)

Example 3 with TLongArrayList

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;
}
Also used : TLongArrayList(gnu.trove.list.array.TLongArrayList)

Example 4 with TLongArrayList

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);
    }
}
Also used : TLongArrayList(gnu.trove.list.array.TLongArrayList) TLongHashSet(gnu.trove.set.hash.TLongHashSet)

Example 5 with TLongArrayList

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();
}
Also used : Entity(net.osmand.osm.edit.Entity) XMLOutputFactory(javax.xml.stream.XMLOutputFactory) TLongArrayList(gnu.trove.list.array.TLongArrayList) Node(net.osmand.osm.edit.Node) Way(net.osmand.osm.edit.Way) EntityId(net.osmand.osm.edit.Entity.EntityId) Relation(net.osmand.osm.edit.Relation) RelationMember(net.osmand.osm.edit.Relation.RelationMember) XMLStreamWriter(javax.xml.stream.XMLStreamWriter) OutputStreamWriter(java.io.OutputStreamWriter) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Aggregations

TLongArrayList (gnu.trove.list.array.TLongArrayList)28 ArrayList (java.util.ArrayList)5 TIntArrayList (gnu.trove.list.array.TIntArrayList)4 Test (org.junit.Test)4 CandidateCellForSweeping (com.palantir.atlasdb.keyvalue.api.CandidateCellForSweeping)3 ImmutableCandidateCellForSweeping (com.palantir.atlasdb.keyvalue.api.ImmutableCandidateCellForSweeping)3 TLongList (gnu.trove.list.TLongList)3 Relation (net.osmand.osm.edit.Relation)3 RelationMember (net.osmand.osm.edit.Relation.RelationMember)3 TByteArrayList (gnu.trove.list.array.TByteArrayList)2 TLongObjectHashMap (gnu.trove.map.hash.TLongObjectHashMap)2 IOException (java.io.IOException)2 Node (net.osmand.osm.edit.Node)2 Way (net.osmand.osm.edit.Way)2 RunMiXCR (com.milaboratory.mixcr.util.RunMiXCR)1 TLongIterator (gnu.trove.iterator.TLongIterator)1 TDoubleArrayList (gnu.trove.list.array.TDoubleArrayList)1 TFloatArrayList (gnu.trove.list.array.TFloatArrayList)1 TShortArrayList (gnu.trove.list.array.TShortArrayList)1 TLongHashSet (gnu.trove.set.hash.TLongHashSet)1