Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 package org.ros.android.view.visualization.layer;
00018
00019 import org.ros.android.view.visualization.Color;
00020 import org.ros.android.view.visualization.Vertices;
00021 import org.ros.android.view.visualization.VisualizationView;
00022 import org.ros.android.view.visualization.XYOrthographicCamera;
00023 import org.ros.message.MessageListener;
00024 import org.ros.namespace.GraphName;
00025 import org.ros.node.ConnectedNode;
00026
00027 import java.util.concurrent.locks.Lock;
00028 import java.util.concurrent.locks.ReentrantLock;
00029
00030 import javax.microedition.khronos.opengles.GL10;
00031
00035 public class GridCellsLayer extends SubscriberLayer<nav_msgs.GridCells> implements TfLayer {
00036
00037 private final Color color;
00038 private final Lock lock;
00039
00040 private GraphName frame;
00041 private XYOrthographicCamera camera;
00042 private boolean ready;
00043 private nav_msgs.GridCells message;
00044
00045 public GridCellsLayer(String topicName, Color color) {
00046 this(GraphName.of(topicName), color);
00047 }
00048
00049 public GridCellsLayer(GraphName topicName, Color color) {
00050 super(topicName, "nav_msgs/GridCells");
00051 this.color = color;
00052 frame = null;
00053 lock = new ReentrantLock();
00054 ready = false;
00055 }
00056
00057 @Override
00058 public void draw(VisualizationView view, GL10 gl) {
00059 if (!ready) {
00060 return;
00061 }
00062 super.draw(view, gl);
00063 lock.lock();
00064 float pointSize =
00065 (float) (Math.max(message.getCellWidth(), message.getCellHeight()) * camera.getZoom());
00066 float[] vertices = new float[3 * message.getCells().size()];
00067 int i = 0;
00068 for (geometry_msgs.Point cell : message.getCells()) {
00069 vertices[i] = (float) cell.getX();
00070 vertices[i + 1] = (float) cell.getY();
00071 vertices[i + 2] = 0.0f;
00072 i += 3;
00073 }
00074 gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
00075 gl.glVertexPointer(3, GL10.GL_FLOAT, 0, Vertices.toFloatBuffer(vertices));
00076 color.apply(gl);
00077 gl.glPointSize(pointSize);
00078 gl.glDrawArrays(GL10.GL_POINTS, 0, message.getCells().size());
00079 gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);
00080 lock.unlock();
00081 }
00082
00083 @Override
00084 public void onStart(final VisualizationView view, ConnectedNode connectedNode) {
00085 super.onStart(view, connectedNode);
00086 getSubscriber().addMessageListener(new MessageListener<nav_msgs.GridCells>() {
00087 @Override
00088 public void onNewMessage(nav_msgs.GridCells data) {
00089 frame = GraphName.of(data.getHeader().getFrameId());
00090 if (view.getFrameTransformTree().lookUp(frame) != null) {
00091 if (lock.tryLock()) {
00092 message = data;
00093 ready = true;
00094 lock.unlock();
00095 }
00096 }
00097 }
00098 });
00099 }
00100
00101 @Override
00102 public GraphName getFrame() {
00103 return frame;
00104 }
00105 }