SLProject  4.2.000
A platform independent 3D computer graphics framework for desktop OS, Android, iOS and online in web browsers
WAIApp Class Reference

Implements app functionality (e.g. scene description, which camera, how to start and use WAISlam) More...

#include <WAIAppTest.h>

Inheritance diagram for WAIApp:
[legend]

Public Types

using CloseAppCallback = std::function< void()>
 

Public Member Functions

 WAIApp ()
 
void init (int screenWidth, int screenHeight, int screenDpi, AppDirectories directories)
 
void initCloseAppCallback (CloseAppCallback cb)
 
void initCamera (SENSCamera *camera)
 
bool update ()
 
void close ()
 
void goBack ()
 
- Public Member Functions inherited from SLInputEventInterface
 SLInputEventInterface (SLInputManager &inputManager)
 
void resize (int sceneViewIndex, int width, int height)
 
void updateScr2fb (int sceneViewIndex)
 
void mouseDown (int sceneViewIndex, SLMouseButton button, int x, int y, SLKey modifier)
 
void mouseMove (int sceneViewIndex, int x, int y)
 
void mouseUp (int sceneViewIndex, SLMouseButton button, int x, int y, SLKey modifier)
 
void doubleClick (int sceneViewIndex, SLMouseButton button, int x, int y, SLKey modifier)
 
void touch2Down (int sceneViewIndex, int x1, int y1, int x2, int y2)
 
void touch2Move (int sceneViewIndex, int x1, int y1, int x2, int y2)
 
void touch2Up (int sceneViewIndex, int x1, int y1, int x2, int y2)
 
void mouseWheel (int sceneViewIndex, int pos, SLKey modifier)
 
void keyPress (int sceneViewIndex, SLKey key, SLKey modifier)
 
void keyRelease (int sceneViewIndex, SLKey key, SLKey modifier)
 
void charInput (int sceneViewIndex, unsigned int character)
 
void longTouch (int sceneViewIndex, int x, int y)
 
void scrCaptureRequest (int sceneViewIndex, std::string outputPath)
 

Private Member Functions

void initSceneCamera ()
 
void initDirectories (AppDirectories directories)
 
void initSceneGraph (int scrWidth, int scrHeight, int dpi)
 
void initIntroScene ()
 
void deleteSceneGraph ()
 

Private Attributes

SENSCamera * _camera = nullptr
 
SLSceneView_sv = nullptr
 
SLCamera_sceneCamera = nullptr
 
SLGLTexture_videoImage = nullptr
 
AppDirectories _dirs
 
CloseAppCallback _closeAppCallback
 
bool _goBackRequested = false
 
bool _initSceneGraphDone = false
 
bool _initIntroSceneDone = false
 

Detailed Description

Implements app functionality (e.g. scene description, which camera, how to start and use WAISlam)

Definition at line 23 of file WAIAppTest.h.

Member Typedef Documentation

◆ CloseAppCallback

using WAIApp::CloseAppCallback = std::function<void()>

Definition at line 26 of file WAIAppTest.h.

Constructor & Destructor Documentation

◆ WAIApp()

WAIApp::WAIApp ( )

Definition at line 30 of file WAIAppTest.cpp.

32 {
33 }
static SLInputManager inputManager
Input events manager.
Definition: AppCommon.h:58
SLInputEventInterface(SLInputManager &inputManager)

Member Function Documentation

◆ close()

void WAIApp::close ( )

Definition at line 196 of file WAIAppTest.cpp.

197 {
199  _initSceneGraphDone = false;
200  _initIntroSceneDone = false;
201 }
void deleteSceneGraph()
Definition: WAIAppTest.cpp:210
bool _initIntroSceneDone
Definition: WAIAppTest.h:65
bool _initSceneGraphDone
Definition: WAIAppTest.h:64

◆ deleteSceneGraph()

void WAIApp::deleteSceneGraph ( )
private

Definition at line 210 of file WAIAppTest.cpp.

211 {
212  // Deletes all remaining sceneviews the current scene instance
213  if (AppCommon::scene)
214  {
215  delete AppCommon::scene;
216  AppCommon::scene = nullptr;
217  }
218 }
static SLScene * scene
Pointer to the one and only SLScene instance.
Definition: AppCommon.h:61

◆ goBack()

void WAIApp::goBack ( )

Definition at line 203 of file WAIAppTest.cpp.

204 {
205  WAIAPP_DEBUG("goBack");
206  // todo: enqueue event
207  _goBackRequested = true;
208 }
#define WAIAPP_DEBUG(...)
Definition: WAIAppTest.cpp:14
bool _goBackRequested
Definition: WAIAppTest.h:63

◆ init()

void WAIApp::init ( int  screenWidth,
int  screenHeight,
int  screenDpi,
AppDirectories  directories 
)

Definition at line 35 of file WAIAppTest.cpp.

36 {
37  WAIAPPSTATE_DEBUG("init");
38  // Utils::initFileLog(directories.logFileDir, true);
39 
41  {
42  initDirectories(directories);
43  initSceneGraph(screenWidth, screenHeight, screenDpi);
44  _initSceneGraphDone = true;
45  }
47  {
49  _initIntroSceneDone = true;
50  }
51 }
#define WAIAPPSTATE_DEBUG(...)
Definition: WAIAppTest.cpp:22
void initIntroScene()
Definition: WAIAppTest.cpp:236
void initDirectories(AppDirectories directories)
Definition: WAIAppTest.cpp:80
void initSceneGraph(int scrWidth, int scrHeight, int dpi)
Definition: WAIAppTest.cpp:93

◆ initCamera()

void WAIApp::initCamera ( SENSCamera *  camera)

Definition at line 58 of file WAIAppTest.cpp.

59 {
60  _camera = camera;
61 
62  /*
63  if (_sv)
64  _sv->setViewportFromRatio(SLVec2i(_camera->getFrameSize().width, _camera->getFrameSize().height), SLViewportAlign::VA_center, true);
65 
66  if (_sceneCamera)
67  {
68  //make sure scene camera is initialized
69  initSceneCamera();
70  }
71 
72  if (!_videoImage)
73  {
74  _videoImage = new SLGLTexture("LiveVideoError.png", GL_LINEAR, GL_LINEAR);
75  _sceneCamera->background().texture(_videoImage);
76  }
77  */
78 }
SENSCamera * _camera
Definition: WAIAppTest.h:52

◆ initCloseAppCallback()

void WAIApp::initCloseAppCallback ( CloseAppCallback  cb)

Definition at line 53 of file WAIAppTest.cpp.

54 {
55  _closeAppCallback = cb;
56 }
CloseAppCallback _closeAppCallback
Definition: WAIAppTest.h:61

◆ initDirectories()

void WAIApp::initDirectories ( AppDirectories  directories)
private

Definition at line 80 of file WAIAppTest.cpp.

81 {
82  WAIAPP_DEBUG("initDirectories");
83  _dirs = directories;
84  // Default paths for all loaded resources
85  SLGLProgram::defaultPath = _dirs.slDataRoot + "/shaders/";
86  SLGLTexture::defaultPath = _dirs.slDataRoot + "/images/textures/";
87  SLGLTexture::defaultPathFonts = _dirs.slDataRoot + "/images/fonts/";
88  CVImage::defaultPath = _dirs.slDataRoot + "/images/textures/";
89  SLAssimpImporter::defaultPath = _dirs.slDataRoot + "/models/";
91 }
static SLstring configPath
Default path for calibration files.
Definition: AppCommon.h:81
AppDirectories _dirs
Definition: WAIAppTest.h:58
std::string writableDir
Definition: WAIAppTest.h:15
std::string slDataRoot
Definition: WAIAppTest.h:17

◆ initIntroScene()

void WAIApp::initIntroScene ( )
private

Definition at line 236 of file WAIAppTest.cpp.

237 {
238  WAIAPP_DEBUG("initIntroScene");
240  // clear old scene content
241  s->init();
242 
243  s->name("Loading scene");
244  s->info("Scene shown while starting application");
245 
246  SLMaterial* m1 = new SLMaterial("m1", SLCol4f::RED);
247 
248  initSceneCamera(); //_sceneCamera is valid now
249 
250  SLLightSpot* light1 = new SLLightSpot(10, 10, 10, 0.3f);
251  light1->ambient(SLCol4f(0.2f, 0.2f, 0.2f));
252  light1->diffuse(SLCol4f(0.8f, 0.8f, 0.8f));
253  light1->specular(SLCol4f(1, 1, 1));
254  light1->attenuation(1, 0, 0);
255 
256  // Because all text objects get their sizes in pixels we have to scale them down
257  SLfloat scale = 0.01f;
258  SLstring txt = "This is text in 3D with font07";
259  SLVec2f size = SLTexFont::font07->calcTextSize(txt);
260  SLNode* t07 = new SLText(txt, SLTexFont::font07);
261  t07->translate(-size.x * 0.5f * scale, 1.0f, 0);
262  t07->scale(scale);
263 
264  txt = "This is text in 3D with font22";
265  size = SLTexFont::font22->calcTextSize(txt);
266  SLNode* t22 = new SLText(txt, SLTexFont::font22);
267  t22->translate(-size.x * 0.5f * scale, -1.2f, 0);
268  t22->scale(scale);
269 
270  // Assemble 3D scene as usual with camera and light
271  SLNode* scene3D = new SLNode("root3D");
272  scene3D->addChild(_sceneCamera);
273  scene3D->addChild(light1);
274  scene3D->addChild(new SLNode(new SLSphere(0.5f, 32, 32, "Sphere", m1)));
275  scene3D->addChild(t07);
276  scene3D->addChild(t22);
277 
279  _sv->doWaitOnIdle(false);
280 
281  s->root3D(scene3D);
282 
283  for (auto sceneView : s->sceneViews())
284  if (sceneView != nullptr)
285  sceneView->onInitialize();
286 
287  /*
288  WAIAPP_DEBUG("initIntroScene");
289  SLScene* s = AppCommon::scene;
290  //clear old scene content
291  s->init();
292 
293  s->name("Loading scene");
294  s->info("Scene shown while starting application");
295 
296  SLMaterial* m1 = new SLMaterial("m1", SLCol4f::RED);
297 
298  SLCamera* cam1 = new SLCamera("Camera 1");
299  cam1->clipNear(0.1f);
300  cam1->clipFar(100);
301  cam1->translation(0, 0, 5);
302  cam1->lookAt(0, 0, 0);
303  cam1->focalDist(5);
304  cam1->background().colors(SLCol4f(0.1f, 0.1f, 0.1f));
305  cam1->setInitialState();
306 
307  SLLightSpot* light1 = new SLLightSpot(10, 10, 10, 0.3f);
308  light1->ambient(SLCol4f(0.2f, 0.2f, 0.2f));
309  light1->diffuse(SLCol4f(0.8f, 0.8f, 0.8f));
310  light1->specular(SLCol4f(1, 1, 1));
311  light1->attenuation(1, 0, 0);
312 
313  // Because all text objects get their sizes in pixels we have to scale them down
314  SLfloat scale = 0.01f;
315  SLstring txt = "This is text in 3D with font07";
316  SLVec2f size = SLTexFont::font07->calcTextSize(txt);
317  SLNode* t07 = new SLText(txt, SLTexFont::font07);
318  t07->translate(-size.x * 0.5f * scale, 1.0f, 0);
319  t07->scale(scale);
320 
321  txt = "This is text in 3D with font09";
322  size = SLTexFont::font09->calcTextSize(txt);
323  SLNode* t09 = new SLText(txt, SLTexFont::font09);
324  t09->translate(-size.x * 0.5f * scale, 0.8f, 0);
325  t09->scale(scale);
326 
327  txt = "This is text in 3D with font12";
328  size = SLTexFont::font12->calcTextSize(txt);
329  SLNode* t12 = new SLText(txt, SLTexFont::font12);
330  t12->translate(-size.x * 0.5f * scale, 0.6f, 0);
331  t12->scale(scale);
332 
333  txt = "This is text in 3D with font20";
334  size = SLTexFont::font20->calcTextSize(txt);
335  SLNode* t20 = new SLText(txt, SLTexFont::font20);
336  t20->translate(-size.x * 0.5f * scale, -0.8f, 0);
337  t20->scale(scale);
338 
339  txt = "This is text in 3D with font22";
340  size = SLTexFont::font22->calcTextSize(txt);
341  SLNode* t22 = new SLText(txt, SLTexFont::font22);
342  t22->translate(-size.x * 0.5f * scale, -1.2f, 0);
343  t22->scale(scale);
344 
345  // Now create 2D text but don't scale it (all sizes in pixels)
346  txt = "This is text in 2D with font16";
347  size = SLTexFont::font16->calcTextSize(txt);
348  SLNode* t2D16 = new SLText(txt, SLTexFont::font16);
349  t2D16->translate(-size.x * 0.5f, 0, 0);
350 
351  // Assemble 3D scene as usual with camera and light
352  SLNode* scene3D = new SLNode("root3D");
353  scene3D->addChild(cam1);
354  scene3D->addChild(light1);
355  scene3D->addChild(new SLNode(new SLSphere(0.5f, 32, 32, "Sphere", m1)));
356  scene3D->addChild(t07);
357  scene3D->addChild(t09);
358  scene3D->addChild(t12);
359  scene3D->addChild(t20);
360  scene3D->addChild(t22);
361 
362  // Assemble 2D scene
363  SLNode* scene2D = new SLNode("root2D");
364  scene2D->addChild(t2D16);
365 
366  _sv->camera(cam1);
367  _sv->doWaitOnIdle(true);
368 
369  s->root3D(scene3D);
370  s->root2D(scene2D);
371  */
372 }
float SLfloat
Definition: SL.h:173
string SLstring
Definition: SL.h:158
SLVec4< SLfloat > SLCol4f
Definition: SLVec4.h:237
void attenuation(const SLfloat kConstant, const SLfloat kLinear, const SLfloat kQuadratic)
Definition: SLLight.h:116
SLLightSpot class for a spot light source.
Definition: SLLightSpot.h:36
SLCol4f diffuse() override
Returns normally _diffuseColor * _diffusePower.
Definition: SLLightSpot.h:85
SLCol4f specular() override
Returns normally _specularColor * _specularPower.
Definition: SLLightSpot.h:86
SLCol4f ambient() override
Return normally _ambientColor * _ambientPower.
Definition: SLLightSpot.h:84
Defines a standard CG material with textures and a shader program.
Definition: SLMaterial.h:56
SLNode represents a node in a hierarchical scene graph.
Definition: SLNode.h:147
void addChild(SLNode *child)
Definition: SLNode.cpp:207
void scale(SLfloat s)
Definition: SLNode.h:640
void translate(const SLVec3f &vec, SLTransformSpace relativeTo=TS_object)
Definition: SLNode.cpp:906
void name(const SLstring &Name)
Definition: SLObject.h:34
The SLScene class represents the top level instance holding the scene structure.
Definition: SLScene.h:47
void root3D(SLNode *root3D)
Definition: SLScene.h:78
void info(SLstring i)
Definition: SLScene.h:93
void init(SLAssetManager *am)
Definition: SLScene.cpp:72
void camera(SLCamera *camera)
Definition: SLSceneView.h:145
void doWaitOnIdle(SLbool doWI)
Definition: SLSceneView.h:149
SLSphere creates a sphere mesh based on SLSpheric w. 180 deg polar angle.
Definition: SLSphere.h:33
SLText creates a mesh using a textured font from SLTexFont.
Definition: SLText.h:30
T x
Definition: SLVec2.h:30
static SLVec4 RED
Definition: SLVec4.h:216
void initSceneCamera()
Definition: WAIAppTest.cpp:220
SLCamera * _sceneCamera
Definition: WAIAppTest.h:55
SLSceneView * _sv
Definition: WAIAppTest.h:54

◆ initSceneCamera()

void WAIApp::initSceneCamera ( )
private

Definition at line 220 of file WAIAppTest.cpp.

221 {
222  if (!_sceneCamera)
223  {
224  _sceneCamera = new SLCamera("Camera 1");
225  _sceneCamera->clipNear(0.1f);
226  _sceneCamera->clipFar(100);
227  _sceneCamera->translation(0, 0, 5);
228  _sceneCamera->lookAt(0, 0, 0);
230  _sceneCamera->background().colors(SLCol4f(0.7f, 0.7f, 0.7f),
231  SLCol4f(0.2f, 0.2f, 0.2f));
233  }
234 }
void colors(const SLCol4f &uniformColor)
Sets a uniform background color.
Active or visible camera node class.
Definition: SLCamera.h:54
void clipFar(const SLfloat cFar)
Definition: SLCamera.h:109
void clipNear(const SLfloat cNear)
Definition: SLCamera.h:108
void focalDist(const SLfloat f)
Definition: SLCamera.h:116
SLBackground & background()
Definition: SLCamera.h:165
void translation(const SLVec3f &pos, SLTransformSpace relativeTo=TS_parent)
Definition: SLNode.cpp:828
void setInitialState()
Definition: SLNode.cpp:1084
void lookAt(SLfloat targetX, SLfloat targetY, SLfloat targetZ, SLfloat upX=0, SLfloat upY=1, SLfloat upZ=0, SLTransformSpace relativeTo=TS_world)
Definition: SLNode.h:652

◆ initSceneGraph()

void WAIApp::initSceneGraph ( int  scrWidth,
int  scrHeight,
int  dpi 
)
private

Definition at line 93 of file WAIAppTest.cpp.

94 {
95  WAIAPP_DEBUG("initSceneGraph");
96  if (!AppCommon::scene)
97  {
98  AppCommon::name = "WAI Demo App";
99  AppCommon::scene = new SLScene("WAI Demo App", nullptr);
100 
101  int screenWidth = scrWidth;
102  int screenHeight = scrHeight;
103 
104  // setupGUI(AppCommon::name, AppCommon::configPath, dpi);
105  // Set default font sizes depending on the dpi no matter if ImGui is used
106  // todo: is this still needed?
107  if (!AppCommon::dpi)
109 
110  _sv = new SLSceneView();
111  _sv->init("SceneView",
112  screenWidth,
113  screenHeight,
114  nullptr,
115  nullptr,
116  nullptr);
117  }
118  else
119  {
120  WAIAPP_WARN("initSceneGraph: SLScene already loaded!");
121  }
122 }
static SLint dpi
Dot per inch resolution of screen.
Definition: AppGLFW.cpp:41
static SLint scrHeight
Window height at start up.
Definition: AppGLFW.cpp:38
static SLint scrWidth
Window width at start up.
Definition: AppGLFW.cpp:37
#define WAIAPP_WARN(...)
Definition: WAIAppTest.cpp:16
static SLstring name
Application name.
Definition: AppCommon.h:72
SceneView class represents a dynamic real time 3D view onto the scene.
Definition: SLSceneView.h:69
void init(SLstring name, SLint screenWidth, SLint screenHeight, void *onWndUpdateCallback, void *onSelectNodeMeshCallback, SLUiInterface *gui, const string &configPath)
Definition: SLSceneView.cpp:64

◆ update()

bool WAIApp::update ( )

Definition at line 124 of file WAIAppTest.cpp.

125 {
127  {
129  _goBackRequested = false;
130  }
131 
132  if (!_initSceneGraphDone)
133  return false;
134 
135  // WAIAPP_DEBUG("render");
137  {
138  if (_camera)
139  {
140  // if (_camera->started())
141  //{
142 
143  //}
144 
145  // copy video image to background
146  SENSFramePtr frame = _camera->getLatestFrame();
147  if (frame)
148  {
149  if (!_videoImage)
150  {
151  if (!_sceneCamera)
152  {
153  // make sure scene camera is initialized
154  initSceneCamera();
155  }
156 
157  if (_sv)
158  _sv->setViewportFromRatio(SLVec2i(_camera->getFrameSize().width,
159  _camera->getFrameSize().height),
161  true);
162 
163  _videoImage = new SLGLTexture("LiveVideoError.png", GL_LINEAR, GL_LINEAR);
165  }
166 
167  WAIAPP_DEBUG("valid frame");
168  cv::Mat& img = frame->imgRGB;
169  _videoImage->copyVideoImage(img.cols,
170  img.rows,
171  CVImage::cv2glPixelFormat(img.type()),
172  img.data,
173  img.isContinuous(),
174  true);
175  }
176  }
177 
178  // update scene
180 
181  // update sceneviews
182  bool needUpdate = false;
183  for (auto sv : AppCommon::scene->sceneViews())
184  if (sv->onPaint() && !needUpdate)
185  needUpdate = true;
186 
187  return needUpdate;
188  }
189  else
190  {
191  WAIAPP_WARN("render: SLScene not initialized!");
192  return false;
193  }
194 }
@ VA_center
Definition: SLEnums.h:255
SLVec2< SLint > SLVec2i
Definition: SLVec2.h:140
void texture(SLGLTexture *backgroundTexture, bool fixAspectRatio=false)
If flag _repeatBlurred is true the texture is not distorted if its size does not fit to screen aspect...
Texture object for OpenGL texturing.
Definition: SLGLTexture.h:110
SLbool copyVideoImage(SLint camWidth, SLint camHeight, CVPixelFormatGL glFormat, SLuchar *data, SLbool isContinuous, SLbool isTopLeft)
Copies the image data from a video camera into the current video image.
bool onUpdate(bool renderTypeIsRT, bool voxelsAreShown, bool forceCPUSkinning)
Updates animations and AABBs.
Definition: SLScene.cpp:124
SLbool onPaint()
void setViewportFromRatio(const SLVec2i &vpRatio, SLViewportAlign vpAlignment, SLbool vpSameAsVideo)
Sets the viewport ratio and the viewport rectangle.
SLGLTexture * _videoImage
Definition: WAIAppTest.h:56

Member Data Documentation

◆ _camera

SENSCamera* WAIApp::_camera = nullptr
private

Definition at line 52 of file WAIAppTest.h.

◆ _closeAppCallback

CloseAppCallback WAIApp::_closeAppCallback
private

Definition at line 61 of file WAIAppTest.h.

◆ _dirs

AppDirectories WAIApp::_dirs
private

Definition at line 58 of file WAIAppTest.h.

◆ _goBackRequested

bool WAIApp::_goBackRequested = false
private

Definition at line 63 of file WAIAppTest.h.

◆ _initIntroSceneDone

bool WAIApp::_initIntroSceneDone = false
private

Definition at line 65 of file WAIAppTest.h.

◆ _initSceneGraphDone

bool WAIApp::_initSceneGraphDone = false
private

Definition at line 64 of file WAIAppTest.h.

◆ _sceneCamera

SLCamera* WAIApp::_sceneCamera = nullptr
private

Definition at line 55 of file WAIAppTest.h.

◆ _sv

SLSceneView* WAIApp::_sv = nullptr
private

Definition at line 54 of file WAIAppTest.h.

◆ _videoImage

SLGLTexture* WAIApp::_videoImage = nullptr
private

Definition at line 56 of file WAIAppTest.h.


The documentation for this class was generated from the following files: