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::shared_ptr<ARTrackerSquare> m_squareTracker;
109#if HAVE_NFT
110 std::shared_ptr<ARTrackerNFT> m_nftTracker;
111#endif
112#if HAVE_2D
113 std::shared_ptr<ARTracker2d> m_twoDTracker;
114#endif
115
116 int m_error;
117 void setError(int error);
118
119public:
120#pragma mark Public API
121 // ------------------------------------------------------------------------------
122 // Public API
123 // ------------------------------------------------------------------------------
124
128 ARController();
129
134
139 const char* getARToolKitVersion();
140
141 int getError();
142
147 bool initialiseBase();
148
149 std::shared_ptr<ARTrackerSquare> getSquareTracker() { return m_squareTracker; };
150#if HAVE_NFT
151 std::shared_ptr<ARTrackerNFT> getNFTTracker() { return m_nftTracker; };
152#endif
153#if HAVE_2D
154 std::shared_ptr<ARTracker2d> get2dTracker() { return m_twoDTracker; };
155#endif
156
162 bool isInited();
163
172 bool startRunning(const char* vconf, const char* cparaName, const char* cparaBuff, const long cparaBuffLen);
173
189 bool startRunningStereo(const char* vconfL, const char* cparaNameL, const char* cparaBuffL, const long cparaBuffLenL,
190 const char* vconfR, const char* cparaNameR, const char* cparaBuffR, const long cparaBuffLenR,
191 const char* transL2RName, const char* transL2RBuff, const long transL2RBuffLen);
192
193 int videoPushInit(int videoSourceIndex, int width, int height, const char *pixelFormat, int cameraIndex, int cameraPosition);
194 int videoPush(int videoSourceIndex,
195 ARUint8 *buf0p, int buf0Size, int buf0PixelStride, int buf0RowStride,
196 ARUint8 *buf1p, int buf1Size, int buf1PixelStride, int buf1RowStride,
197 ARUint8 *buf2p, int buf2Size, int buf2PixelStride, int buf2RowStride,
198 ARUint8 *buf3p, int buf3Size, int buf3PixelStride, int buf3RowStride);
199 int videoPushFinal(int videoSourceIndex);
200
211 bool videoParameters(const int videoSourceIndex, int *width, int *height, AR_PIXEL_FORMAT *pixelFormat);
212
217 bool isRunning();
218
223 bool stopRunning();
224
230 bool shutdown();
231
242 bool projectionMatrix(const int videoSourceIndex, const ARdouble projectionNearPlane, const ARdouble projectionFarPlane, ARdouble proj[16]);
243
257 bool projectionForViewportSizeAndFittingMode(const int videoSourceIndex, const ARVideoSource::Size viewportSize, const ARVideoSource::ScalingMode scalingMode, const ARdouble projectionNearPlane, const ARdouble projectionFarPlane, ARdouble proj[16]);
258
259 bool drawVideoInit(const int videoSourceIndex);
260
261 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]);
262
263 bool drawVideo(const int videoSourceIndex);
264
265 bool drawVideoFinal(const int videoSourceIndex);
266
281 int addTrackable(const std::string& cfgs);
282
288 bool removeTrackable(int UID);
289
295
300 unsigned int countTrackables() const;
301
306 unsigned int countTrackables(ARTrackable::TrackableType trackableType) const;
307
312 std::vector<std::shared_ptr<ARTrackable>> getAllTrackables();
313
319 std::shared_ptr<ARTrackable> findTrackable(int UID);
320
326 bool capture();
327
336 bool updateTextureRGBA32(const int videoSourceIndex, uint32_t *buffer);
337
348 bool update();
349
358 bool updateDebugTexture32(const int videoSourceIndex, uint32_t* buffer);
359
366 bool getPatternImage(int patternID, uint32_t* buffer);
367
391 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]);
392
393
394#if HAVE_2D
401 bool load2DTrackerImageDatabase(const char* databaseFileName);
402
408 bool save2DTrackerImageDatabase(const char* databaseFileName);
409#endif // HAVE_2D
410
411};
412
413
414#endif // !ARCONTROLLER_H
artoolkitX core routines.
unsigned char ARUint8
Definition: ar.h:92
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:800
bool startRunning(const char *vconf, const char *cparaName, const char *cparaBuff, const long cparaBuffLen)
Start video capture and tracking.
Definition: ARController.cpp:157
int addTrackable(const std::string &cfgs)
Adds a trackable as specified in the given configuration string.
Definition: ARController.cpp:643
int videoPushFinal(int videoSourceIndex)
Definition: ARController.cpp:890
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:497
int removeAllTrackables()
Clears the collection of trackables.
Definition: ARController.cpp:719
bool getPatternImage(int patternID, uint32_t *buffer)
Populates the provided color buffer with the image for the specified pattern.
std::vector< std::shared_ptr< ARTrackable > > getAllTrackables()
Returns all trackables.
Definition: ARController.cpp:782
int videoPushInit(int videoSourceIndex, int width, int height, const char *pixelFormat, int cameraIndex, int cameraPosition)
Definition: ARController.cpp:844
bool isRunning()
Returns true if video capture and tracking is running.
Definition: ARController.cpp:620
bool projectionForViewportSizeAndFittingMode(const int videoSourceIndex, const ARVideoSource::Size viewportSize, const ARVideoSource::ScalingMode scalingMode, const ARdouble projectionNearPlane, const ARdouble projectionFarPlane, ARdouble proj[16])
Populates the provided array with the ARToolKit projection matrix, so that the projection maps to the...
Definition: ARController.cpp:588
unsigned int countTrackables(ARTrackable::TrackableType trackableType) const
Returns the number of currently loaded trackables of the specified type.
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:76
bool stopRunning()
Video capture and tracking stops, but trackables are still valid and can be configured.
Definition: ARController.cpp:397
bool isInited()
Report whether artoolkit was initialized and a trackable can be added.
Definition: ARController.cpp:614
bool drawVideo(const int videoSourceIndex)
Definition: ARController.cpp:526
std::shared_ptr< ARTrackerSquare > getSquareTracker()
Definition: ARController.h:149
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:291
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:562
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:195
bool initialiseBase()
Start trackable management so trackables can be added and removed.
Definition: ARController.cpp:108
bool capture()
Requests the capture of a new frame from the video source(s).
Definition: ARController.cpp:270
unsigned int countTrackables() const
Returns the number of currently loaded trackables.
Definition: ARController.cpp:735
bool shutdown()
Stop, if running.
Definition: ARController.cpp:434
ARController()
Constructor.
Definition: ARController.cpp:63
bool update()
Performs tracking and updates all trackables.
Definition: ARController.cpp:304
bool drawVideoFinal(const int videoSourceIndex)
Definition: ARController.cpp:541
const char * getARToolKitVersion()
Returns a string containing the artoolkitX version, such as "10.0.0".
Definition: ARController.cpp:82
int videoPush(int videoSourceIndex, ARUint8 *buf0p, int buf0Size, int buf0PixelStride, int buf0RowStride, ARUint8 *buf1p, int buf1Size, int buf1PixelStride, int buf1RowStride, ARUint8 *buf2p, int buf2Size, int buf2PixelStride, int buf2RowStride, ARUint8 *buf3p, int buf3Size, int buf3PixelStride, int buf3RowStride)
Definition: ARController.cpp:865
int getError()
Definition: ARController.cpp:95
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:625
bool drawVideoInit(const int videoSourceIndex)
Definition: ARController.cpp:477
bool removeTrackable(int UID)
Removes the trackable with the given ID.
Definition: ARController.cpp:689
std::shared_ptr< ARTrackable > findTrackable(int UID)
Searches the collection of trackables for the given ID.
Definition: ARController.cpp:764
TrackableType
Definition: ARTrackable.h:78
A video source provides video frames to the artoolkitX tracking module.
Definition: ARVideoSource.h:53
ScalingMode
Definition: ARVideoSource.h:138
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
Definition: ARVideoSource.h:133