Renderer.java
Go to the documentation of this file.
1 /*
2  * Copyright 2014 Google Inc. All Rights Reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.introlab.rtabmap;
18 
19 import java.util.Vector;
20 import java.util.concurrent.locks.ReentrantLock;
21 
22 import android.app.Activity;
23 import android.app.ProgressDialog;
24 import android.opengl.GLES20;
25 import android.opengl.GLSurfaceView;
26 import android.opengl.Matrix;
27 import android.util.Log;
28 import android.widget.Toast;
29 
30 import javax.microedition.khronos.egl.EGLConfig;
31 import javax.microedition.khronos.opengles.GL10;
32 
33 // Renderer renders graphic content. This includes the point cloud,
34 // ground grid, camera frustum, camera axis, and trajectory based on the Tango
35 // device's pose.
36 public class Renderer implements GLSurfaceView.Renderer {
37 
38  private final float[] mtrxProjection = new float[16];
39  private final float[] mtrxView = new float[16];
40  private final float[] mtrxProjectionAndView = new float[16];
41 
42  private TextManager mTextManager = null;
43  private float mSurfaceHeight = 0.0f;
44  private float mTextColor = 1.0f;
45  private int mOffset = 0;
46  private ARCoreSharedCamera mCamera = null;
48 
49  private Vector<TextObject> mTexts;
50 
51  private static RTABMapActivity mActivity;
53  mActivity = c;
55  }
56 
57  private ProgressDialog mProgressDialog = null;
58  private Toast mToast = null;
59 
60  private boolean mTextChanged = false;
61  private ReentrantLock mTextLock = new ReentrantLock();
62 
63  public void setProgressDialog(ProgressDialog progressDialog)
64  {
65  mProgressDialog = progressDialog;
66  }
67 
68  public void setToast(Toast toast)
69  {
70  mToast = toast;
71  }
72 
73  public void setOffset(int offset)
74  {
75  mOffset = offset;
76  }
77 
78  public void setCamera(ARCoreSharedCamera camera)
79  {
80  mCamera = camera;
81  if(mCamera!=null)
82  {
85  }
86  }
87 
88  // Render loop of the Gl context.
89  public void onDrawFrame(GL10 useGLES20instead) {
90 
91  synchronized (this) {
93  {
94  int step = 0;
95  try
96  {
97  if(mCamera!=null)
98  {
99  step=1;
100  mCamera.updateGL();
101 
102  }
103 
104  step=2;
105 
107 
108  if(mTextManager!=null)
109  {
110  step=3;
111  if(mTextChanged)
112  {
113  mTextChanged = false;
114  Vector<TextObject> txtcollection = new Vector<TextObject>();
115 
116  mTextLock.lock();
117  try {
118  if(mTexts.size() > 0)
119  {
120  txtcollection.addAll(mTexts);
121  }
122  } finally {
123  mTextLock.unlock();
124  }
125 
126  // Prepare the text for rendering
127  mTextManager.PrepareDraw(txtcollection);
128  }
129 
130  float[] mvp = new float[16];
131  Matrix.translateM(mvp, 0, mtrxProjectionAndView, 0, 0, mOffset, 0);
132  mTextManager.Draw(mvp);
133  }
134  step=4;
135  if(value != 0 && mProgressDialog != null && mProgressDialog.isShowing())
136  {
137  mActivity.runOnUiThread(new Runnable() {
138  public void run() {
139  if(!RTABMapActivity.DISABLE_LOG) Log.i("RTABMapActivity", "Renderer: dismiss dialog, value received=" + String.valueOf(value));
140  mProgressDialog.dismiss();
142  }
143  });
144  }
145  if(value==-1)
146  {
147  mActivity.runOnUiThread(new Runnable() {
148  public void run() {
149  if(mToast!=null)
150  {
151  mToast.makeText(mActivity.getApplicationContext(), String.format("Out of Memory!"), Toast.LENGTH_SHORT).show();
152  }
153  }
154  });
155  }
156  else if(value==-2)
157  {
158  mActivity.runOnUiThread(new Runnable() {
159  public void run() {
160  if(mToast!=null)
161  {
162  mToast.makeText(mActivity.getApplicationContext(), String.format("Rendering Error!"), Toast.LENGTH_SHORT).show();
163  }
164  }
165  });
166  }
167  }
168  catch(final Exception e)
169  {
170  final int stepF = step;
171  mActivity.runOnUiThread(new Runnable() {
172  public void run() {
173  if(mToast!=null)
174  {
175  String msg = String.format("Rendering error! (exception=%s) step=%d", e.getMessage(), stepF);
176  Log.e("RTABMapActivity", msg);
177  mToast.makeText(mActivity.getApplicationContext(), msg, Toast.LENGTH_LONG).show();
178  }
179  }
180 
181  });
182  }
183  }
184  }
185  }
186 
187  // Called when the surface size changes.
188  public void onSurfaceChanged(GL10 useGLES20instead, int width, int height) {
189 
191  {
193  }
194 
196  if(mCamera!=null)
197  {
199  }
200 
201  mSurfaceHeight = (float)height;
202 
203  // Clear our matrices
204  for(int i=0;i<16;i++)
205  {
206  mtrxProjection[i] = 0.0f;
207  mtrxView[i] = 0.0f;
208  mtrxProjectionAndView[i] = 0.0f;
209  }
210 
211  // Setup our screen width and height for normal sprite translation.
212  Matrix.orthoM(mtrxProjection, 0, 0f, width, 0.0f, height, 0, 50);
213 
214  // Set the camera position (View matrix)
215  Matrix.setLookAtM(mtrxView, 0, 0f, 0f, 1f, 0f, 0f, 0f, 0f, 1.0f, 0.0f);
216 
217  // Calculate the projection and view transformation
218  Matrix.multiplyMM(mtrxProjectionAndView, 0, mtrxProjection, 0, mtrxView, 0);
219  }
220 
221  // Called when the surface is created or recreated.
222  public void onSurfaceCreated(GL10 useGLES20instead, EGLConfig config) {
223 
225  {
227  }
228 
229  // Create our text manager
232  }
233 
234  public void updateTexts(String[] texts)
235  {
236  if(mTextManager != null && mSurfaceHeight > 0.0f)
237  {
238  Vector<TextObject> textObjects = new Vector<TextObject>();
240  if(texts != null)
241  {
242  for(int i=0;i<texts.length; ++i)
243  {
244  if(texts[i]!=null && texts[i].length()>0)
245  {
246  TextObject txt = new TextObject(texts[i], 0, offset);
247  textObjects.add(txt);
248  }
250  }
251  }
252 
253  mTextLock.lock();
254  try {
255  mTexts = textObjects;
256  } finally {
257  mTextLock.unlock();
258  }
259 
260  mTextChanged = true;
261  }
262  }
263 
264  public void setTextColor(float color)
265  {
266  mTextColor = color;
267  if(mTextManager != null)
268  {
270  }
271  }
272 }
com.introlab.rtabmap.Renderer.mTextColor
float mTextColor
Definition: Renderer.java:44
com.introlab.rtabmap.TextManager.setColor
void setColor(float color)
Definition: TextManager.java:419
glm::length
GLM_FUNC_DECL genType::value_type length(genType const &x)
run
void run(class_loader::ClassLoader *loader)
com.introlab.rtabmap.Renderer.onSurfaceCreated
void onSurfaceCreated(GL10 useGLES20instead, EGLConfig config)
Definition: Renderer.java:222
com.introlab.rtabmap.Renderer.updateTexts
void updateTexts(String[] texts)
Definition: Renderer.java:234
c
Scalar Scalar * c
com.introlab.rtabmap.Renderer.mtrxProjectionAndView
final float[] mtrxProjectionAndView
Definition: Renderer.java:40
com.introlab.rtabmap.Renderer.mToast
Toast mToast
Definition: Renderer.java:58
com.introlab.rtabmap.Renderer
Definition: Renderer.java:36
com.introlab.rtabmap.Renderer.mtrxView
final float[] mtrxView
Definition: Renderer.java:39
com.introlab.rtabmap.TextManager.Draw
void Draw(float[] m)
Definition: TextManager.java:253
com.introlab.rtabmap.Renderer.setProgressDialog
void setProgressDialog(ProgressDialog progressDialog)
Definition: Renderer.java:63
com.introlab.rtabmap.DisplayRotationHelper.onDisplayChanged
void onDisplayChanged(int displayId)
Definition: DisplayRotationHelper.java:163
com.introlab.rtabmap.TextManager.PrepareDraw
void PrepareDraw(Vector< TextObject > txtcollection)
Definition: TextManager.java:234
com.introlab.rtabmap.Renderer.mActivity
static RTABMapActivity mActivity
Definition: Renderer.java:51
com.introlab.rtabmap.Renderer.setToast
void setToast(Toast toast)
Definition: Renderer.java:68
com.introlab.rtabmap.DisplayRotationHelper
Definition: DisplayRotationHelper.java:36
Matrix
Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor > Matrix
com.introlab.rtabmap.RTABMapLib
Definition: RTABMapLib.java:15
com.introlab.rtabmap.Renderer.mCamera
ARCoreSharedCamera mCamera
Definition: Renderer.java:46
com.introlab.rtabmap.Renderer.mDisplayRotationHelper
DisplayRotationHelper mDisplayRotationHelper
Definition: Renderer.java:47
com.introlab.rtabmap.TextManager
Definition: TextManager.java:22
com.introlab.rtabmap.Renderer.setCamera
void setCamera(ARCoreSharedCamera camera)
Definition: Renderer.java:78
com.introlab.rtabmap.Renderer.setOffset
void setOffset(int offset)
Definition: Renderer.java:73
com.introlab.rtabmap.Renderer.mProgressDialog
ProgressDialog mProgressDialog
Definition: Renderer.java:57
com.introlab.rtabmap.Renderer.mTextLock
ReentrantLock mTextLock
Definition: Renderer.java:61
com.introlab.rtabmap.DisplayRotationHelper.onSurfaceChanged
void onSurfaceChanged(int width, int height)
Definition: DisplayRotationHelper.java:75
com.introlab.rtabmap.Renderer.onDrawFrame
void onDrawFrame(GL10 useGLES20instead)
Definition: Renderer.java:89
com.introlab.rtabmap.RTABMapActivity.DISABLE_LOG
static boolean DISABLE_LOG
Definition: RTABMapActivity.java:114
com.introlab.rtabmap.Renderer.mTextManager
TextManager mTextManager
Definition: Renderer.java:42
step
def step(data, isam, result, truth, currPoseIndex, isamArgs=())
com.introlab.rtabmap.RTABMapLib.initGlContent
static native void initGlContent(long nativeApplication)
com.introlab.rtabmap.RTABMapActivity.nativeApplication
static long nativeApplication
Definition: RTABMapActivity.java:110
com.introlab.rtabmap.Renderer.mTextChanged
boolean mTextChanged
Definition: Renderer.java:60
offset
set noclip points set clip one set noclip two set bar set border lt lw set xdata set ydata set zdata set x2data set y2data set boxwidth set dummy y set format x g set format y g set format x2 g set format y2 g set format z g set angles radians set nogrid set key title set key left top Right noreverse box linetype linewidth samplen spacing width set nolabel set noarrow set nologscale set logscale x set set pointsize set encoding default set nopolar set noparametric set set set set surface set nocontour set clabel set mapping cartesian set nohidden3d set cntrparam order set cntrparam linear set cntrparam levels auto set cntrparam points set size set set xzeroaxis lt lw set x2zeroaxis lt lw set yzeroaxis lt lw set y2zeroaxis lt lw set tics in set ticslevel set tics set mxtics default set mytics default set mx2tics default set my2tics default set xtics border mirror norotate autofreq set ytics border mirror norotate autofreq set ztics border nomirror norotate autofreq set nox2tics set noy2tics set timestamp bottom norotate offset
f
Point2(* f)(const Point3 &, OptionalJacobian< 2, 3 >)
com.introlab.rtabmap.RTABMapLib.setupGraphic
static native void setupGraphic(long nativeApplication, int width, int height)
e
Array< double, 1, 3 > e(1./3., 0.5, 2.)
com.introlab.rtabmap.Renderer.Renderer
Renderer(RTABMapActivity c)
Definition: Renderer.java:52
com.introlab.rtabmap.Renderer.mSurfaceHeight
float mSurfaceHeight
Definition: Renderer.java:43
com.introlab.rtabmap.ARCoreSharedCamera.updateGL
void updateGL()
Definition: ARCoreSharedCamera.java:653
com.introlab.rtabmap.TextObject
Definition: TextObject.java:4
camera
Camera camera(Pose3(Rot3().retract(Vector3(0.1, 0.2, 0.3)), Point3(0, 5, 0)), Cal3Bundler0(1, 0, 0))
com.introlab.rtabmap.RTABMapActivity.resetNoTouchTimer
void resetNoTouchTimer()
Definition: RTABMapActivity.java:2203
com.introlab.rtabmap.ARCoreSharedCamera
Definition: ARCoreSharedCamera.java:49
com.introlab.rtabmap.Renderer.mTexts
Vector< TextObject > mTexts
Definition: Renderer.java:49
float
float
com.introlab.rtabmap.Renderer.mOffset
int mOffset
Definition: Renderer.java:45
txt
txt
com.introlab.rtabmap.RTABMapLib.render
static native int render(long nativeApplication)
com.introlab.rtabmap.Renderer.setTextColor
void setTextColor(float color)
Definition: Renderer.java:264
value
value
i
int i
com.introlab.rtabmap.DisplayRotationHelper.updateSessionIfNeeded
void updateSessionIfNeeded(ARCoreSharedCamera session)
Definition: DisplayRotationHelper.java:89
com.introlab.rtabmap.TextManager.getMaxTextHeight
float getMaxTextHeight()
Definition: TextManager.java:56
com.introlab.rtabmap.Renderer.mtrxProjection
final float[] mtrxProjection
Definition: Renderer.java:38
com.introlab.rtabmap.Renderer.onSurfaceChanged
void onSurfaceChanged(GL10 useGLES20instead, int width, int height)
Definition: Renderer.java:188
msg
msg
com.introlab.rtabmap.RTABMapActivity
Definition: RTABMapActivity.java:107


rtabmap
Author(s): Mathieu Labbe
autogenerated on Thu Jul 25 2024 02:50:15