use of aimax.osm.data.entities.MapNode in project aima-java by aimacode.
the class MapViewPopup method actionPerformed.
@Override
public void actionPerformed(ActionEvent ae) {
if (ae.getSource() == entityInfoMenuItem) {
MapNode mNode = pane.getRenderer().getNextNode(x, y);
if (mNode != null)
pane.showMapEntityInfoDialog(mNode, pane.isDebugModeEnabled());
} else if (ae.getSource() == clearMenuItem) {
pane.getMap().clearMarkersAndTracks();
} else if (ae.getSource() == createMarkerMenuItem) {
PositionPanel panel = new PositionPanel();
int res = JOptionPane.showConfirmDialog(pane, panel, "Specify a Position", JOptionPane.OK_CANCEL_OPTION);
if (res == JOptionPane.OK_OPTION) {
float lat = panel.getLat();
float lon = panel.getLon();
if (!Float.isNaN(lat) && !Float.isNaN(lon)) {
pane.getMap().addMarker(lat, lon);
pane.adjustToCenter(lat, lon);
}
}
} else if (ae.getSource() == removeMarkerMenuItem) {
pane.removeNearestMarker(x, y);
} else if (ae.getSource() == loadMarkersMenuItem) {
XMLDecoder decoder = null;
try {
File xmlFile = null;
if (getFileChooser().showDialog(pane, "Load Markers") == JFileChooser.APPROVE_OPTION) {
xmlFile = getFileChooser().getSelectedFile();
if (!xmlFile.getPath().contains("."))
xmlFile = new File(xmlFile.getPath() + ".xml");
}
if (xmlFile != null && xmlFile.exists()) {
pane.getMap().clearMarkersAndTracks();
decoder = new XMLDecoder(new BufferedInputStream(new FileInputStream(xmlFile)));
int size = (Integer) decoder.readObject();
for (int i = 0; i < size; i++) {
WritablePosition pos = (WritablePosition) decoder.readObject();
pane.getMap().addMarker(pos.getLat(), pos.getLon());
}
pane.fireMapViewEvent(new MapViewEvent(pane, MapViewEvent.Type.MARKER_ADDED));
}
} catch (IOException e) {
e.printStackTrace();
} finally {
if (decoder != null)
decoder.close();
}
} else if (ae.getSource() == saveMarkersMenuItem) {
XMLEncoder encoder = null;
try {
File xmlFile = null;
if (getFileChooser().showDialog(pane, "Save Markers") == JFileChooser.APPROVE_OPTION) {
xmlFile = getFileChooser().getSelectedFile();
if (!xmlFile.getPath().contains("."))
xmlFile = new File(xmlFile.getPath() + ".xml");
encoder = new XMLEncoder(new BufferedOutputStream(new FileOutputStream(xmlFile)));
encoder.writeObject(pane.getMap().getMarkers().size());
for (MapNode node : pane.getMap().getMarkers()) encoder.writeObject(new WritablePosition(node));
}
} catch (IOException e) {
e.printStackTrace();
} finally {
if (encoder != null)
encoder.close();
}
} else if (ae.getSource() == functionsMenuItem) {
JOptionPane.showMessageDialog(pane, MapViewPane.FUNCTION_DESCRIPTION.split("\\|"), "Function Description", JOptionPane.INFORMATION_MESSAGE);
} else if (ae.getSource() == debugMenuItem) {
pane.enableDebugMode(debugMenuItem.isSelected());
}
}
use of aimax.osm.data.entities.MapNode in project aima-java by aimacode.
the class OsmAgentController method initAgents.
/** Creates new agents and adds them to the current environment. */
protected void initAgents(MessageLogger logger) {
List<MapNode> markers = map.getOsmMap().getMarkers();
if (markers.size() < 2) {
logger.log("Error: Please set two markers with mouse-left.");
return;
}
String[] locs = new String[markers.size()];
for (int i = 0; i < markers.size(); i++) {
MapNode node = markers.get(i);
Point2D pt = new Point2D(node.getLon(), node.getLat());
locs[i] = map.getNearestLocation(pt);
}
MapAgentFrame.SelectionState state = frame.getSelection();
heuristic = createHeuristic(state.getIndex(MapAgentFrame.HEURISTIC_SEL), locs[1]);
search = SearchFactory.getInstance().createSearch(state.getIndex(MapAgentFrame.SEARCH_SEL), state.getIndex(MapAgentFrame.Q_SEARCH_IMPL_SEL), heuristic);
Agent agent = null;
switch(state.getIndex(MapAgentFrame.AGENT_SEL)) {
case 0:
agent = new SimpleMapAgent(map, env, search, new String[] { locs[1] });
break;
case 1:
Problem<String, MoveToAction> p = new BidirectionalMapProblem(map, null, locs[1]);
OnlineSearchProblem<String, MoveToAction> osp = new GeneralProblem<>(null, p::getActions, null, p::testGoal, p::getStepCosts);
agent = new LRTAStarAgent<>(osp, MapFunctions.createPerceptToStateFunction(), s -> heuristic.applyAsDouble(new Node<>(s)));
break;
}
env.addAgent(agent, locs[0]);
}
use of aimax.osm.data.entities.MapNode in project aima-java by aimacode.
the class DefaultTrack method addNode.
@Override
public void addNode(Position pos) {
int idx = trkpts.isEmpty() ? 0 : (int) trkpts.get(trkpts.size() - 1).getId() + 1;
MapNode node = new DefaultMapNode(idx);
node.setPosition(pos.getLat(), pos.getLon());
addNode(node);
}
use of aimax.osm.data.entities.MapNode in project aima-java by aimacode.
the class OsmAgentBaseApp method simulate.
/** Starts the experiment. */
public void simulate() {
List<MapNode> markers = map.getOsmMap().getMarkers();
if (markers.size() < 2) {
simPaneCtrl.setStatus("Error: Please set at least two markers with mouse-left.");
} else {
List<String> locations = new ArrayList<>(markers.size());
for (MapNode node : markers) {
Point2D pt = new Point2D(node.getLon(), node.getLat());
locations.add(map.getNearestLocation(pt));
}
Agent agent = createAgent(locations);
env = createEnvironment();
env.addEnvironmentView(new TrackUpdater());
env.addAgent(agent, locations.get(0));
if (simPaneCtrl.getParam(PARAM_SEARCH).isPresent())
env.notifyViews("Using " + simPaneCtrl.getParamValue(PARAM_SEARCH));
while (!env.isDone() && !CancelableThread.currIsCanceled()) {
env.step();
simPaneCtrl.waitAfterStep();
}
envViewCtrl.notify("");
// simPaneCtrl.setStatus(search.getMetrics().toString());
}
}
use of aimax.osm.data.entities.MapNode in project aima-java by aimacode.
the class MapPaneCtrl method handleMouseEvent.
protected void handleMouseEvent(MouseEvent event) {
if (event.getEventType() == MouseEvent.MOUSE_PRESSED) {
xDrag = event.getX();
yDrag = event.getY();
dragActive = false;
} else if (event.getEventType() == MouseEvent.MOUSE_DRAGGED) {
adjust(event.getX() - xDrag, event.getY() - yDrag);
xDrag = event.getX();
yDrag = event.getY();
dragActive = true;
} else if (event.getEventType() == MouseEvent.MOUSE_CLICKED && !dragActive) {
if (event.getButton() == MouseButton.PRIMARY) {
CoordTransformer tr = getTransformer();
getMap().addMarker(tr.lat((int) event.getY()), tr.lon((int) event.getX()));
} else if (event.getButton() == MouseButton.SECONDARY) {
getMap().clearMarkersAndTracks();
} else if (event.getButton() == MouseButton.MIDDLE) {
MapNode mNode = getRenderer().getNextNode((int) event.getX(), (int) event.getY());
if (mNode != null)
showMapEntityInfoDialog(mNode, true);
}
}
// hack...
currCanvas.requestFocus();
}
Aggregations