ARX  1.0
The next-generation open source augmented reality toolkit.
Loading...
Searching...
No Matches
ARController.h
Go to the documentation of this file.
1/*
2 * ARController.h
3 * artoolkitX
4 *
5 * A C++ class encapsulating core controller functionality of artoolkitX.
6 *
7 * This file is part of artoolkitX.
8 *
9 * artoolkitX is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU Lesser General Public License as published by
11 * the Free Software Foundation, either version 3 of the License, or
12 * (at your option) any later version.
13 *
14 * artoolkitX is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU Lesser General Public License for more details.
18 *
19 * You should have received a copy of the GNU Lesser General Public License
20 * along with artoolkitX. If not, see <http://www.gnu.org/licenses/>.
21 *
22 * As a special exception, the copyright holders of this library give you
23 * permission to link this library with independent modules to produce an
24 * executable, regardless of the license terms of these independent modules, and to
25 * copy and distribute the resulting executable under terms of your choice,
26 * provided that you also meet, for each linked independent module, the terms and
27 * conditions of the license of that module. An independent module is a module
28 * which is neither derived from nor based on this library. If you modify this
29 * library, you may extend this exception to your version of the library, but you
30 * are not obligated to do so. If you do not wish to do so, delete this exception
31 * statement from your version.
32 *
33 * Copyright 2018 Realmax, Inc.
34 * Copyright 2015 Daqri, LLC.
35 * Copyright 2010-2015 ARToolworks, Inc.
36 *
37 * Author(s): Philip Lamb, Julian Looser.
38 *
39 */
40
41
42#ifndef ARCONTROLLER_H
43#define ARCONTROLLER_H
44
45#include <ARX/Platform.h>
46#include <ARX/AR/ar.h>
47#include <ARX/ARVideoSource.h>
48#include <ARX/ARVideoView.h>
49#include <ARX/ARTrackerSquare.h>
50#if HAVE_NFT
51# include <ARX/ARTrackerNFT.h>
52#endif
53#if HAVE_2D
54# include <ARX/ARTracker2d.h>
55#endif
56#include <ARX/ARTrackable.h>
57
58
59#include <vector>
60#include <memory>
61#include <stdio.h>
62#include <stdlib.h>
63#include <stdint.h>
64#include <math.h>
65#include <string.h>
66#if !defined(_WINRT)
67# include <pthread.h>
68#else
69# define pthread_mutex_t CRITICAL_SECTION
70# define pthread_mutex_init(pm, a) InitializeCriticalSectionEx(pm, 4000, CRITICAL_SECTION_NO_DEBUG_INFO)
71# define pthread_mutex_lock(pm) EnterCriticalSection(pm)
72# define pthread_mutex_unlock(pm) LeaveCriticalSection(pm)
73# define pthread_mutex_destroy(pm) DeleteCriticalSection(pm)
74#endif
75
81
82private:
83#pragma mark Private types and instance variables
84 // ------------------------------------------------------------------------------
85 // Private types and instance variables.
86 // ------------------------------------------------------------------------------
87
88 typedef enum {
89 NOTHING_INITIALISED,
90 BASE_INITIALISED,
91 WAITING_FOR_VIDEO,
92 DETECTION_RUNNING
93 } ARToolKitState;
94
95 ARToolKitState state;
96 bool stateWaitingMessageLogged;
97
98 char* versionString;
99
100 ARVideoSource *m_videoSource0;
101 ARVideoSource *m_videoSource1;
102 ARdouble m_transL2R[3][4];
103 bool m_videoSourceIsStereo;
104 AR2VideoTimestampT m_updateFrameStamp0;
105 AR2VideoTimestampT m_updateFrameStamp1;
106 ARVideoView *m_arVideoViews[2];
107
108 std::vector<ARTrackable *> m_trackables;
109
110 bool doSquareMarkerDetection;
111 std::shared_ptr<ARTrackerSquare> m_squareTracker;
112#if HAVE_NFT
113 bool doNFTMarkerDetection;
114 std::shared_ptr<ARTrackerNFT> m_nftTracker;
115#endif
116#if HAVE_2D
117 bool doTwoDMarkerDetection;
118 std::shared_ptr<ARTracker2d> m_twoDTracker;
119#endif
120 int m_error;
121 void setError(int error);
122
123#pragma mark Private methods.
124 // ------------------------------------------------------------------------------
125 // Private methods.
126 // ------------------------------------------------------------------------------
127
128 //
129 // Internal trackable management.
130 //
131
137 bool addTrackable(ARTrackable* trackable);
138
144 bool removeTrackable(ARTrackable* trackable);
145
146
147public:
148#pragma mark Public API
149 // ------------------------------------------------------------------------------
150 // Public API
151 // ------------------------------------------------------------------------------
152
156 ARController();
157
162
167 const char* getARToolKitVersion();
168
169 int getError();
170
175 bool initialiseBase();
176
177 std::shared_ptr<ARTrackerSquare> getSquareTracker() { return m_squareTracker; };
178#if HAVE_NFT
179 std::shared_ptr<ARTrackerNFT> getNFTTracker() { return m_nftTracker; };
180#endif
181#if HAVE_2D
182 std::shared_ptr<ARTracker2d> get2dTracker() { return m_twoDTracker; };
183#endif
184
190 bool isInited();
191
200 bool startRunning(const char* vconf, const char* cparaName, const char* cparaBuff, const long cparaBuffLen);
201
217 bool startRunningStereo(const char* vconfL, const char* cparaNameL, const char* cparaBuffL, const long cparaBuffLenL,
218 const char* vconfR, const char* cparaNameR, const char* cparaBuffR, const long cparaBuffLenR,
219 const char* transL2RName, const char* transL2RBuff, const long transL2RBuffLen);
220
221#if ARX_TARGET_PLATFORM_ANDROID
222 jint androidVideoPushInit(JNIEnv *env, jobject obj, jint videoSourceIndex, jint width, jint height, const char *pixelFormat, jint camera_index, jint camera_face);
223 jint androidVideoPush1(JNIEnv *env, jobject obj, jint videoSourceIndex, jbyteArray buf, jint bufSize);
224 jint androidVideoPush2(JNIEnv *env, jobject obj, jint videoSourceIndex,
225 jobject buf0, jint buf0PixelStride, jint buf0RowStride,
226 jobject buf1, jint buf1PixelStride, jint buf1RowStride,
227 jobject buf2, jint buf2PixelStride, jint buf2RowStride,
228 jobject buf3, jint buf3PixelStride, jint buf3RowStride);
229 jint androidVideoPushFinal(JNIEnv *env, jobject obj, jint videoSourceIndex);
230#endif
231
242 bool videoParameters(const int videoSourceIndex, int *width, int *height, AR_PIXEL_FORMAT *pixelFormat);
243
248 bool isRunning();
249
254 bool stopRunning();
255
261 bool shutdown();
262
273 bool projectionMatrix(const int videoSourceIndex, const ARdouble projectionNearPlane, const ARdouble projectionFarPlane, ARdouble proj[16]);
274
275 bool drawVideoInit(const int videoSourceIndex);
276
277 bool drawVideoSettings(const int videoSourceIndex, const int width, const int height, const bool rotate90, const bool flipH, const bool flipV, const ARVideoView::HorizontalAlignment hAlign, const ARVideoView::VerticalAlignment vAlign, const ARVideoView::ScalingMode scalingMode, int32_t viewport[4]);
278
279 bool drawVideo(const int videoSourceIndex);
280
281 bool drawVideoFinal(const int videoSourceIndex);
282
297 int addTrackable(const std::string& cfgs);
298
304 bool removeTrackable(int UID);
305
311
316 unsigned int countTrackables() const;
317
322 unsigned int countTrackables(ARTrackable::TrackableType trackableType) const;
323
329 ARTrackable* getTrackableAtIndex(unsigned int index);
330
336 ARTrackable* findTrackable(int UID);
337
343 bool capture();
344
353 bool updateTextureRGBA32(const int videoSourceIndex, uint32_t *buffer);
354
365 bool update();
366
375 bool updateDebugTexture32(const int videoSourceIndex, uint32_t* buffer);
376
383 bool getPatternImage(int patternID, uint32_t* buffer);
384
408 bool loadOpticalParams(const char *optical_param_name, const char *optical_param_buff, const long optical_param_buffLen, const ARdouble projectionNearPlane, const ARdouble projectionFarPlane, ARdouble *fovy_p, ARdouble *aspect_p, ARdouble m[16], ARdouble p[16]);
409
410
411#if HAVE_2D
418 bool load2DTrackerImageDatabase(const char* databaseFileName);
419
425 bool save2DTrackerImageDatabase(const char* databaseFileName);
426#endif // HAVE_2D
427
428};
429
430
431#endif // !ARCONTROLLER_H
artoolkitX core routines.
double ARdouble
Definition: ar.h:99
Wrapper for artoolkitX functionality.
Definition: ARController.h:80
bool loadOpticalParams(const char *optical_param_name, const char *optical_param_buff, const long optical_param_buffLen, const ARdouble projectionNearPlane, const ARdouble projectionFarPlane, ARdouble *fovy_p, ARdouble *aspect_p, ARdouble m[16], ARdouble p[16])
Loads an optical parameters structure from file or from buffer.
Definition: ARController.cpp:855
bool startRunning(const char *vconf, const char *cparaName, const char *cparaBuff, const long cparaBuffLen)
Start video capture and tracking.
Definition: ARController.cpp:165
bool drawVideoSettings(const int videoSourceIndex, const int width, const int height, const bool rotate90, const bool flipH, const bool flipV, const ARVideoView::HorizontalAlignment hAlign, const ARVideoView::VerticalAlignment vAlign, const ARVideoView::ScalingMode scalingMode, int32_t viewport[4])
Definition: ARController.cpp:505
int removeAllTrackables()
Clears the collection of trackables.
Definition: ARController.cpp:768
ARTrackable * findTrackable(int UID)
Searches the collection of trackables for the given ID.
Definition: ARController.cpp:840
bool getPatternImage(int patternID, uint32_t *buffer)
Populates the provided color buffer with the image for the specified pattern.
bool isRunning()
Returns true if video capture and tracking is running.
Definition: ARController.cpp:601
bool updateDebugTexture32(const int videoSourceIndex, uint32_t *buffer)
Populates the provided buffer with the current contents of the debug image.
~ARController()
Destructor.
Definition: ARController.cpp:84
bool stopRunning()
Video capture and tracking stops, but trackables are still valid and can be configured.
Definition: ARController.cpp:405
bool isInited()
Report whether artoolkit was initialized and a trackable can be added.
Definition: ARController.cpp:595
bool drawVideo(const int videoSourceIndex)
Definition: ARController.cpp:534
std::shared_ptr< ARTrackerSquare > getSquareTracker()
Definition: ARController.h:177
bool updateTextureRGBA32(const int videoSourceIndex, uint32_t *buffer)
Asks the video source to push the most recent frame into the passed-in buffer.
Definition: ARController.cpp:299
bool projectionMatrix(const int videoSourceIndex, const ARdouble projectionNearPlane, const ARdouble projectionFarPlane, ARdouble proj[16])
Populates the provided array with the ARToolKit projection matrix.
Definition: ARController.cpp:570
bool startRunningStereo(const char *vconfL, const char *cparaNameL, const char *cparaBuffL, const long cparaBuffLenL, const char *vconfR, const char *cparaNameR, const char *cparaBuffR, const long cparaBuffLenR, const char *transL2RName, const char *transL2RBuff, const long transL2RBuffLen)
Start stereo video capture and tracking.
Definition: ARController.cpp:203
bool initialiseBase()
Start trackable management so trackables can be added and removed.
Definition: ARController.cpp:116
bool capture()
Requests the capture of a new frame from the video source(s).
Definition: ARController.cpp:278
unsigned int countTrackables() const
Returns the number of currently loaded trackables.
Definition: ARController.cpp:794
bool shutdown()
Stop, if running.
Definition: ARController.cpp:442
ARController()
Constructor.
Definition: ARController.cpp:63
bool update()
Performs tracking and updates all trackables.
Definition: ARController.cpp:312
bool drawVideoFinal(const int videoSourceIndex)
Definition: ARController.cpp:549
const char * getARToolKitVersion()
Returns a string containing the artoolkitX version, such as "10.0.0".
Definition: ARController.cpp:90
ARTrackable * getTrackableAtIndex(unsigned int index)
Returns the trackable at the specified index.
Definition: ARController.cpp:834
int getError()
Definition: ARController.cpp:103
bool videoParameters(const int videoSourceIndex, int *width, int *height, AR_PIXEL_FORMAT *pixelFormat)
Reports width, height and pixel format of a video source.
Definition: ARController.cpp:606
bool drawVideoInit(const int videoSourceIndex)
Definition: ARController.cpp:485
Base class for supported trackable types.
Definition: ARTrackable.h:54
TrackableType
Definition: ARTrackable.h:78
A video source provides video frames to the artoolkitX tracking module.
Definition: ARVideoSource.h:53
ARVideoView draws the output of an ARVideoSource to a rendering context, usually for the purposes of ...
Definition: ARVideoView.h:55
HorizontalAlignment
Definition: ARVideoView.h:63
ScalingMode
Definition: ARVideoView.h:73
VerticalAlignment
Definition: ARVideoView.h:68
A structure to hold a timestamp in seconds and microseconds, with arbitrary epoch.
Definition: ar.h:139