@Override public void readConstData(ByteBuffer in) throws IOException { int numberOfEntries = in.getInt(); for (int i = 0; i < numberOfEntries; i++) { VisBusStop stop = new VisBusStop(); stop.id = ByteBufferUtils.getString(in); String linkIdString = ByteBufferUtils.getString(in); if (!linkIdString.isEmpty()) { stop.linkId = linkIdString; } stop.x = in.getDouble(); stop.y = in.getDouble(); if (this.drawer != null) { this.drawer.stops.add(stop); } } }
private void writeSignalSystems(ByteBuffer out){ out.putInt(this.signalGroups.getSignalGroupDataBySignalSystemId().size()); for (Id<SignalSystem> systemId : this.signalGroups.getSignalGroupDataBySignalSystemId().keySet()){ ByteBufferUtils.putString(out, systemId.toString()); Map<Id<SignalGroup>, SignalGroupData> groups = this.signalGroups.getSignalGroupDataBySystemId(systemId); out.putInt(groups.size()); for (SignalGroupData group : groups.values()){ ByteBufferUtils.putString(out, group.getId().toString()); out.putInt(group.getSignalIds().size()); for (Id<Signal> signalId : group.getSignalIds()){ ByteBufferUtils.putString(out, signalId.toString()); SignalData signal = signalSystems.getSignalSystemData().get(systemId).getSignalData().get(signalId); ByteBufferUtils.putString(out, signal.getLinkId().toString()); if (signal.getLaneIds() == null || signal.getLaneIds().isEmpty()){ out.putInt(0); out.putInt(signal.getLaneIds().size()); for (Id<Lane> laneId : signal.getLaneIds()){ ByteBufferUtils.putString(out, laneId.toString()); out.putInt(signal.getTurningMoveRestrictions().size()); for (Id<Link> outLinkId : signal.getTurningMoveRestrictions()){ ByteBufferUtils.putString(out, outLinkId.toString());
@Override public void readConstData(ByteBuffer in) throws IOException { int noLinks = in.getInt(); for (int i = 0; i < noLinks; i++){ //read link data VisLinkWLanes lanesLinkData = (VisLinkWLanes) ByteBufferUtils.getObject(in); this.drawer.addLaneLinkData(lanesLinkData); } this.laneModelBuilder.connect(this.drawer.getLanesLinkData()); }
/** * Tests {@link ByteBufferUtils#putString(java.nio.ByteBuffer, String)} and * {@link ByteBufferUtils#getString(java.nio.ByteBuffer)}. */ public void testPutGetString() { final ByteBuffer buffer = ByteBuffer.allocate(100); buffer.putInt(5); ByteBufferUtils.putString(buffer, "foo bar"); buffer.putChar('?'); ByteBufferUtils.putString(buffer, "Hello World"); buffer.putChar('!'); buffer.flip(); assertEquals(5, buffer.getInt()); assertEquals("foo bar", ByteBufferUtils.getString(buffer)); assertEquals('?', buffer.getChar()); assertEquals("Hello World", ByteBufferUtils.getString(buffer)); assertEquals('!', buffer.getChar()); assertFalse(buffer.hasRemaining()); }
/** * Tests {@link ByteBufferUtils#putObject(java.nio.ByteBuffer, Serializable)} and * {@link ByteBufferUtils#getObject(java.nio.ByteBuffer)}. */ public void testPutGetObject() { final ByteBuffer buffer = ByteBuffer.allocate(100); buffer.putInt(5); ByteBufferUtils.putObject(buffer, "foo bar"); buffer.putChar('?'); ByteBufferUtils.putObject(buffer, "Hello World"); buffer.putChar('!'); buffer.flip(); assertEquals(5, buffer.getInt()); assertEquals("foo bar", ByteBufferUtils.getObject(buffer)); assertEquals('?', buffer.getChar()); assertEquals("Hello World", ByteBufferUtils.getObject(buffer)); assertEquals('!', buffer.getChar()); assertFalse(buffer.hasRemaining()); }
@Override public void writeConstData(ByteBuffer out) throws IOException { //write the data for the links out.putInt(this.network.getVisLinks().size()); for (VisLink visLink : this.network.getVisLinks().values()) { LanesToLinkAssignment l2l = null; if (this.lanes != null){ l2l = this.lanes.getLanesToLinkAssignments().get(visLink.getLink().getId()); } List<ModelLane> la = null; if (l2l != null) { la = LanesUtils.createLanes(visLink.getLink(), l2l); } VisLinkWLanes otfLink = this.laneModelBuilder.createVisLinkLanes(OTFServerQuadTree.getOTFTransformation(), visLink, config.qsim().getNodeOffset(), la); //write link data ByteBufferUtils.putObject(out, otfLink); } }
private static void writeAgent(AgentSnapshotInfo agInfo, ByteBuffer out) { String id = agInfo.getId().toString(); ByteBufferUtils.putString(out, id); Point2D.Double point = OTFServerQuadTree.transform(new Coord(agInfo.getEasting(), agInfo.getNorthing())); out.putFloat((float) point.getX()); out.putFloat((float) point.getY()); out.putInt(agInfo.getAgentState().ordinal() ) ; out.putInt(agInfo.getUserDefined()); out.putFloat((float)agInfo.getColorValueBetweenZeroAndOne()); }
@Override public void readConstData(ByteBuffer in) throws IOException { String id = ByteBufferUtils.getString(in); this.quad[0] = new Point2D.Float(in.getFloat(), in.getFloat()); this.quad[1] = new Point2D.Float(in.getFloat(), in.getFloat()); this.nrLanes = in.getInt(); this.id = id.toCharArray(); }
private void writeSignalGroupStates(ByteBuffer out){ out.putInt(this.signalTracker.getSignalGroupEvents().size()); for (SignalGroupStateChangedEvent e : this.signalTracker.getSignalGroupEvents()){ ByteBufferUtils.putString(out, e.getSignalSystemId().toString()); ByteBufferUtils.putString(out, e.getSignalGroupId().toString()); SignalGroupState state = e.getNewState(); if (state.equals(SignalGroupState.GREEN)){ out.putInt(1); } else if (state.equals(SignalGroupState.RED)){ out.putInt(0); } else if (state.equals(SignalGroupState.REDYELLOW)){ out.putInt(2); } else if (state.equals(SignalGroupState.YELLOW)){ out.putInt(3); } else if (state.equals(SignalGroupState.OFF)){ out.putInt(4); } } this.signalTracker.getSignalGroupEvents().clear(); }
@Override public void readDynData(ByteBuffer in, SceneGraph graph) throws IOException { int noEvents = in.getInt(); for (int i = 0; i < noEvents; i++){ String systemId = ByteBufferUtils.getString(in); String groupId = ByteBufferUtils.getString(in); int stateInt = in.getInt(); SignalGroupState state = null; if (stateInt == 1){ state = SignalGroupState.GREEN; } else if (stateInt == 0){ state = SignalGroupState.RED; } else if (stateInt == 2){ state = SignalGroupState.REDYELLOW; } else if (stateInt == 3){ state = SignalGroupState.YELLOW; } else if (stateInt == 4){ state = SignalGroupState.OFF; } this.drawer.updateGreenState(systemId, groupId, state); } } }
private static void writeAgent(AgentSnapshotInfo pos, ByteBuffer out) { String id = pos.getId().toString(); ByteBufferUtils.putString(out, id); Point2D.Double point = OTFServerQuadTree.transform(new Coord(pos.getEasting(), pos.getNorthing())); out.putFloat((float) point.getX()); out.putFloat((float) point.getY()); out.putInt(pos.getUserDefined()); out.putFloat((float) pos.getColorValueBetweenZeroAndOne()); out.putInt(pos.getAgentState().ordinal()); }
private void readAgent(ByteBuffer in, SceneGraph graph) { String id = ByteBufferUtils.getString(in); float x = in.getFloat(); float y = in.getFloat(); int int1 = in.getInt() ; int int2 = in.getInt() ; float float1 = in.getFloat() ; AgentSnapshotInfo agInfo = snapshotFactory.createAgentSnapshotInfo(Id.create(id, Person.class), x, y, 0., 0.) ; agInfo.setAgentState( al[int1] ) ; agInfo.setUserDefined( int2 ) ; agInfo.setColorValueBetweenZeroAndOne(float1); graph.getAgentPointLayer().addAgent(agInfo); }
@Override public void writeConstData(ByteBuffer out) throws IOException { out.putInt(this.schedule.getFacilities().size()); for (TransitStopFacility facility : this.schedule.getFacilities().values()) { ByteBufferUtils.putString(out, facility.getId().toString()); if (facility.getLinkId() != null) { // yyyy would most probably make sense to have something that generates coordinates for facilities Link link = this.network.getLinks().get( facility.getLinkId() ) ; if ( link==null ) { log.warn( " link not found; linkId: " + facility.getLinkId() ) ; ByteBufferUtils.putString(out,""); Point2D.Double point = OTFServerQuadTree.transform(facility.getCoord()); out.putDouble(point.getX()); out.putDouble(point.getY()); } else { ByteBufferUtils.putString(out, facility.getLinkId().toString()); AgentSnapshotInfo ps = agentSnapshotInfoFactory.createAgentSnapshotInfo(Id.create(facility.getId(), Person.class), link, 0.9*link.getLength(), 0) ; Point2D.Double point = OTFServerQuadTree.transform(new Coord(ps.getEasting(), ps.getNorthing())); out.putDouble(point.getX()) ; out.putDouble(point.getY()) ; } } else { ByteBufferUtils.putString(out,""); Point2D.Double point = OTFServerQuadTree.transform(facility.getCoord()); out.putDouble(point.getX()); out.putDouble(point.getY()); } } }
private void readAgent(ByteBuffer in, SceneGraph sceneGraph) { // yyyy there is a very similar method in OTFAgentsListHandler. with a more robust format, they should be united. kai, apr'10 String id = ByteBufferUtils.getString(in); float x = in.getFloat(); float y = in.getFloat(); int userdefined = in.getInt(); float colorValue = in.getFloat(); int state = in.getInt(); AgentSnapshotInfo agInfo = snapshotFactory.createAgentSnapshotInfo(Id.create(id, Person.class), x, y, 0., 0.); agInfo.setColorValueBetweenZeroAndOne(colorValue); agInfo.setUserDefined(userdefined); agInfo.setAgentState(AgentState.values()[state]); sceneGraph.getAgentPointLayer().addAgent(agInfo); }
@Override public void writeConstData(ByteBuffer out) throws IOException { String id = this.src.getLink().getId().toString(); ByteBufferUtils.putString(out, id); //subtract minEasting/Northing somehow! Point2D.Double.Double linkStart = OTFServerQuadTree.transform(this.src.getLink().getFromNode().getCoord()); Point2D.Double.Double linkEnd = OTFServerQuadTree.transform(this.src.getLink().getToNode().getCoord()); out.putFloat((float) linkStart.x); out.putFloat((float) linkStart.y); out.putFloat((float) linkEnd.x); out.putFloat((float) linkEnd.y); if ( OTFVisConfigGroup.NUMBER_OF_LANES.equals(OTFClientControl.getInstance().getOTFVisConfig().getLinkWidthIsProportionalTo()) ) { out.putInt(NetworkUtils.getNumberOfLanesAsInt(0, this.src.getLink())); } else if ( OTFVisConfigGroup.CAPACITY.equals(OTFClientControl.getInstance().getOTFVisConfig().getLinkWidthIsProportionalTo()) ) { out.putInt( 1 + (int)(2.*this.src.getLink().getCapacity()/3600.) ) ; // yyyyyy 3600. is a magic number (the default of the capacity period attribute in Network) but I cannot get to the network (where "capacityPeriod" resides). // Please do better if you know better. kai, jun'11 } else { throw new RuntimeException("I do not understand. Aborting ..." ) ; } }
private void readSignalSystems(ByteBuffer in){ int noSignalSystems = in.getInt(); for (int i = 0; i < noSignalSystems; i++){ String systemId = ByteBufferUtils.getString(in); VisSignalSystem otfsystem = new VisSignalSystem(systemId); this.drawer.addOTFSignalSystem(otfsystem); String groupId = ByteBufferUtils.getString(in); VisSignalGroup otfgroup = new VisSignalGroup(systemId, groupId); otfsystem.addOTFSignalGroup(otfgroup); int noSignals = in.getInt(); for (int k = 0; k < noSignals; k++){ String signalId = ByteBufferUtils.getString(in); String linkId = ByteBufferUtils.getString(in); VisLinkWLanes link = this.drawer.getLanesLinkData().get(linkId); VisSignal signal = new VisSignal(systemId, signalId); String laneId = ByteBufferUtils.getString(in); VisLane laneData = link.getLaneData().get(laneId); laneData.addSignal(signal); String toLinkId = ByteBufferUtils.getString(in); VisLinkWLanes toLink = this.drawer.getLanesLinkData().get(toLinkId); signal.addTurningMoveRestriction(toLink);