private async Task Setup()
        {
            // Initialize ARToolKit wrapper
            _arWrapper = new ARWrapper();

            _arWrapper.arwRegisterLogCallback(Helper.Log);
            if (!_arWrapper.arwInitialiseARWithOptions(CurrentTemplateSize, CurrentTemplateCountMax))
            {
                throw new InvalidOperationException("Failed to initialize ARToolKit.");
            }
            string artVersion;
            if (!_arWrapper.arwGetARToolKitVersion(out artVersion))
            {
                throw new InvalidOperationException("Failed to get ARToolKit version.");
            }
            Helper.Log("ARToolkit version {0}", artVersion);

            // Init ViewModel for UI data binding. Use Adaptive image binarization mode as default
            _arWrapperViewModel = Resources["WrapperVm"] as ArWrapperViewModel;
            if (_arWrapperViewModel != null)
            {
                _arWrapperViewModel.ArWrapper = _arWrapper;
                _arWrapperViewModel.SelectedThresholdMode = _arWrapperViewModel.ThresholdModes.FirstOrDefault(t => t.Mode == ArThresholdMode.Manual);
                _arWrapperViewModel.ManualThresholdValue = 120;
            }

            // Load marker
            SetupMarker();

            // Setup rendering members
            _projectionMatrix = new float[16];
            _markerModelViewMatrix = new float[16];
            _bufferAr = new uint[DesiredVideoWidth * DesiredVideoHeight];
            ArD3dPanel.Context = new ArD3dDeviceContext();
            _cube = new ArD3dCube();
            _markerMask = new ArD3dCube { TranslateZ = -0.5f, Scale = 60.0f };
            _videoImage = new ArD3dImage();

            // Init video with calibration data
            // TODO: Run on a background thread since the inner working of the WinMC implementation use Wait() on async op which will fail on the UI thread
            await Task.Run(async () =>
            {
                await StartCapturing();
                StartProcessing();
                //  _isSnapshotRestored = await Helper.RestoreSnapshot(_bufferAr, _markerModelViewMatrix);
            });
            Window.Current.CoreWindow.KeyUp += CoreWindowOnKeyUp;
        }
Exemple #2
0
        private async Task Setup()
        {
            // Initialize ARToolKitComponent wrapper
            _arWrapper = new ARWrapper();

            // Setup the logging delegate to log the message from ARToolKit and init ARToolKit
            _arWrapper.arwRegisterLogCallback(Helper.Log);
            if (!_arWrapper.arwInitialiseARWithOptions(CurrentTemplateSize, CurrentTemplateCountMax))
            {
                throw new InvalidOperationException("Failed to initialize ARToolKit.");
            }
            // Log the ARToolKit version
            string artVersion;
            if (!_arWrapper.arwGetARToolKitVersion(out artVersion))
            {
                throw new InvalidOperationException("Failed to get ARToolKit version.");
            }
            Helper.Log("ARToolkit version {0}", artVersion);

            // Init ViewModel for UI data binding. Use Adaptive image binarization mode as default
            _arWrapperViewModel = Resources["WrapperVm"] as ArWrapperViewModel;
            if (_arWrapperViewModel != null)
            {
                _arWrapperViewModel.ArWrapper = _arWrapper;
                _arWrapperViewModel.SelectedThresholdMode = _arWrapperViewModel.ThresholdModes.FirstOrDefault(t => t.Mode == ArThresholdMode.Manual);
                _arWrapperViewModel.ManualThresholdValue = 120;
            }

            // Load marker
            await SetupMarker();

            // Setup rendering members which store the projection, model-view matrix and the video frame buffer
            _projectionMatrix = new float[16];
            _markerModelViewMatrix = new float[16];
            _bufferAr = new uint[DesiredVideoWidth * DesiredVideoHeight];

            // Init the D3D device context wrapper and the used instances from ArgsubD3D
            ArD3dPanel.Context = new ArD3dDeviceContext();
            _cube = new ArD3dCube();
            _videoImage = new ArD3dImage();

            // Init video with calibration data and start the processing loop
            await Task.Run(async () =>
            {
                await StartCapturing();
                StartProcessing();
            });

            // Hook up windows key event handler
            Window.Current.CoreWindow.KeyUp += CoreWindowOnKeyUp;
        }