SLProject  4.2.000
A platform independent 3D computer graphics framework for desktop OS, Android, iOS and online in web browsers
WAIInterface.cpp
Go to the documentation of this file.
1 #include <WAI.h>
2 #include <WAIMath.h>
3 
4 static WAI::WAI wai("");
5 static WAI::ModeOrbSlam2* mode = nullptr;
6 
8 {
9  float x, y, z;
10 };
11 
12 extern "C" {
13 WAI_API void wai_setDataRoot(const char* dataRoot)
14 {
15  WAI_LOG("dataroot set to %s", dataRoot);
16  wai.setDataRoot(dataRoot);
17 }
18 
19 WAI_API void wai_setMode(WAI::ModeType modeType)
20 {
21  WAI_LOG("setMode called");
22  mode = (WAI::ModeOrbSlam2*)wai.setMode(modeType);
23 }
24 
25 WAI_API void wai_getMapPoints(WAIMapPointCoordinate** mapPointCoordinatePtr,
26  int* mapPointCount)
27 {
28  if (!mode)
29  {
30  WAI_LOG("mode not set. Call wai_setMode first.");
31  return;
32  }
33 
34  std::vector<WAIMapPoint*> mapPoints = mode->getMapPoints();
35  *mapPointCoordinatePtr = (WAIMapPointCoordinate*)malloc(mapPoints.size() * sizeof(WAIMapPointCoordinate));
36  WAIMapPointCoordinate* mapPointCoordinate = *mapPointCoordinatePtr;
37 
38  int count = 0;
39 
40  for (WAIMapPoint* mapPoint : mapPoints)
41  {
42  if (!mapPoint->isBad())
43  {
44  *mapPointCoordinate = {
45  mapPoint->worldPosVec().x,
46  mapPoint->worldPosVec().y,
47  mapPoint->worldPosVec().z,
48  };
49 
50  mapPointCoordinate++;
51  count++;
52  }
53  }
54 
55  *mapPointCount = count;
56 }
57 
58 WAI_API void wai_releaseMapPoints(WAIMapPointCoordinate** mapPointCoordinatePtr)
59 {
60  delete *mapPointCoordinatePtr;
61 }
62 
63 WAI_API void wai_activateSensor(WAI::SensorType sensorType, void* sensorInfo)
64 {
65  WAI_LOG("activateSensor called");
66  wai.activateSensor(sensorType, sensorInfo);
67 }
68 
69 WAI_API void wai_updateCamera(WAI::CameraFrame* frameRGB, WAI::CameraFrame* frameGray)
70 {
71  WAI_LOG("updateCamera called");
72  cv::Mat cvFrameRGB = cv::Mat(frameRGB->height,
73  frameRGB->width,
74  CV_8UC3,
75  frameRGB->memory,
76  frameRGB->pitch);
77  cv::Mat cvFrameGray = cv::Mat(frameGray->height,
78  frameGray->width,
79  CV_8UC1,
80  frameGray->memory,
81  frameGray->pitch);
82 
83  WAI::CameraData sensorData = {&cvFrameGray, &cvFrameRGB};
84 
85  wai.updateSensor(WAI::SensorType_Camera, &sensorData);
86 }
87 
89 {
90  WAI_LOG("whereAmI called");
91  bool result = 0;
92 
93  cv::Mat cvPose = cv::Mat(4, 4, CV_32F);
94  result = wai.whereAmI(&cvPose);
95 
96  if (result)
97  {
98  WAI_LOG("WAI knows where I am");
99  for (int y = 0; y < 4; y++)
100  {
101  for (int x = 0; x < 4; x++)
102  {
103  pose->e[x][y] = cvPose.at<float>(x, y);
104  }
105  }
106  }
107 
108  return result;
109 }
110 
111 WAI_API int wai_getState(char* buffer, int size)
112 {
113  WAI_LOG("getState called");
114  int result = 0;
115 
116  if (mode)
117  {
118  std::string state = mode->getPrintableState();
119 
120  if ((state.size() + 1) < size)
121  {
122  size = state.size() + 1;
123  }
124 
125  result = size;
126  char* c = buffer;
127  const char* s = state.c_str();
128 
129  strncpy(c, s, size);
130  }
131 
132  return result;
133 }
134 
135 WAI_API void wai_registerDebugCallback(DebugLogCallback callback)
136 {
137  registerDebugCallback(callback);
138 }
139 }
#define WAI_API
Definition: WAIHelper.h:36
WAI_API void wai_activateSensor(WAI::SensorType sensorType, void *sensorInfo)
WAI_API void wai_updateCamera(WAI::CameraFrame *frameRGB, WAI::CameraFrame *frameGray)
WAI_API int wai_getState(char *buffer, int size)
WAI_API void wai_setMode(WAI::ModeType modeType)
static WAI::WAI wai("")
static WAI::ModeOrbSlam2 * mode
Definition: WAIInterface.cpp:5
WAI_API bool wai_whereAmI(WAI::M4x4 *pose)
WAI_API void wai_setDataRoot(const char *dataRoot)
WAI_API void wai_registerDebugCallback(DebugLogCallback callback)
WAI_API void wai_getMapPoints(WAIMapPointCoordinate **mapPointCoordinatePtr, int *mapPointCount)
WAI_API void wai_releaseMapPoints(WAIMapPointCoordinate **mapPointCoordinatePtr)
The SLScene class represents the top level instance holding the scene structure.
Definition: SLScene.h:47
std::string getPrintableState()
std::vector< WAIMapPoint * > getMapPoints()
float e[4][4]
Definition: WAIMath.h:136