Skip to content

Commit 37411fe

Browse files
committed
Beginnings of preferences window for macOS.
1 parent 490e3c6 commit 37411fe

File tree

6 files changed

+334
-10
lines changed

6 files changed

+334
-10
lines changed

calib_camera.cpp

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,18 @@
6767
#include <AR6/ARUtil/time.h>
6868
#include <AR6/ARG/arg.h>
6969

70-
#include <SDL2/SDL.h>
71-
7270
#include "fileUploader.h"
7371
#include "calc.h"
7472
#include "flow.h"
7573
#include "Eden/EdenMessage.h"
7674
#include "Eden/EdenGLFont.h"
7775

76+
#if TARGET_PLATFORM_MACOS
77+
# include "macOS/PrefsWindowController.h"
78+
#endif
79+
80+
#include "calib_camera.h"
81+
7882
// ============================================================================
7983
// Types
8084
// ============================================================================
@@ -147,6 +151,9 @@ static int gChessboardCornerNumY = 0;
147151
static int gCalibImageNum = 0;
148152
static float gChessboardSquareWidth = 0.0f;
149153

154+
static void *gPreferences = NULL;
155+
Uint32 gSDLEventPreferencesChanged = 0;
156+
150157
static int gCameraIndex = 0;
151158
static bool gCameraIsFrontFacing = false;
152159

@@ -166,12 +173,12 @@ FILE_UPLOAD_HANDLE_t *fileUploadHandle = NULL;
166173

167174
// Video acquisition and rendering.
168175
//AR2VideoParamT *gVid = NULL;
169-
ARVideoSource *vs = nullptr;
170-
ARView *vv = nullptr;
176+
static ARVideoSource *vs = nullptr;
177+
static ARView *vv = nullptr;
171178

172179

173180
// Marker detection.
174-
long gCallCountMarkerDetect = 0;
181+
static long gCallCountMarkerDetect = 0;
175182

176183
// Window and GL context.
177184
static SDL_GLContext gSDLContext = NULL;
@@ -238,6 +245,7 @@ int main(int argc, char *argv[])
238245
return -1;
239246
}
240247

248+
241249
// Create a window.
242250
gSDLWindow = SDL_CreateWindow("ARToolKit6 Camera Calibration Utility",
243251
SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
@@ -281,6 +289,13 @@ int main(int argc, char *argv[])
281289
}
282290
fileUploaderTickle(fileUploadHandle);
283291

292+
#if TARGET_PLATFORM_MACOS
293+
// Preferences.
294+
gPreferences = initPreferences();
295+
gCameraIndex = getCameraIndex();
296+
#endif
297+
gSDLEventPreferencesChanged = SDL_RegisterEvents(1);
298+
284299
// Calibration prefs.
285300
if( gChessboardCornerNumX == 0 ) gChessboardCornerNumX = CHESSBOARD_CORNER_NUM_X;
286301
if( gChessboardCornerNumY == 0 ) gChessboardCornerNumY = CHESSBOARD_CORNER_NUM_Y;
@@ -338,7 +353,11 @@ int main(int argc, char *argv[])
338353
flowHandleEvent(EVENT_BACK_BUTTON);
339354
} else if (ev.key.keysym.sym == SDLK_SPACE) {
340355
flowHandleEvent(EVENT_TOUCH);
356+
} else if ((ev.key.keysym.sym == SDLK_COMMA && (ev.key.keysym.mod & KMOD_LGUI)) || ev.key.keysym.sym == SDLK_p) {
357+
showPreferences(gPreferences);
341358
}
359+
} else if (gSDLEventPreferencesChanged != 0 && ev.type == gSDLEventPreferencesChanged) {
360+
// Re-read preferences.
342361
}
343362
}
344363

@@ -358,6 +377,15 @@ int main(int argc, char *argv[])
358377
gCameraIndex = 0;
359378
gCameraIsFrontFacing = false;
360379
AR2VideoParamT *vid = vs->getAR2VideoParam();
380+
ARVideoSourceInfoListT *sil = ar2VideoCreateSourceInfoList(VCONF);
381+
if (!sil) ARLOGe("No video source info list returned.\n");
382+
else {
383+
for (int sil_i = 0; sil_i < sil->count; sil_i++) {
384+
ARVideoSourceInfoT si = sil->info[sil_i];
385+
ARLOGe("Source %d name:'%s', model:'%s', UID:'%s'.\n", sil_i, si.name, si.model, si.UID);
386+
}
387+
}
388+
361389
if (vid->module == AR_VIDEO_MODULE_AVFOUNDATION) {
362390
int frontCamera;
363391
if (ar2VideoGetParami(vid, AR_VIDEO_PARAM_AVFOUNDATION_CAMERA_POSITION, &frontCamera) >= 0) {
@@ -394,9 +422,7 @@ int main(int argc, char *argv[])
394422
vv->setFlipV(contentFlipV);
395423
vv->setScalingMode(ARView::ScalingMode::SCALE_MODE_FIT);
396424
vv->initWithVideoSource(*vs, contextWidth, contextHeight);
397-
#ifdef DEBUG
398-
ARLOGe("Content %dx%d (wxh) will display in GL context %dx%d%s.\n", vs->getVideoWidth(), vs->getVideoHeight(), contextWidth, contextHeight, (contentRotate90 ? " rotated" : ""));
399-
#endif
425+
ARLOGi("Content %dx%d (wxh) will display in GL context %dx%d%s.\n", vs->getVideoWidth(), vs->getVideoHeight(), contextWidth, contextHeight, (contentRotate90 ? " rotated" : ""));
400426
vv->getViewport(gViewport);
401427

402428
// Setup a route for rendering the mono background image.

calib_camera.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@
4040
*/
4141

4242
#include "fileUploader.h"
43+
#include <SDL2/SDL.h>
44+
4345

4446
#ifdef __cplusplus
4547
extern "C" {
@@ -50,6 +52,7 @@ extern bool capture(const int capturedImageNum);
5052
extern void calib(ARParam *param_out, ARdouble *err_min_out, ARdouble *err_avg_out, ARdouble *err_max_out);
5153
extern void saveParam(const ARParam *param, ARdouble err_min, ARdouble err_avg, ARdouble err_max);
5254

55+
extern Uint32 gSDLEventPreferencesChanged;
5356
#ifdef __cplusplus
5457
}
5558
#endif

macOS/ARToolKit6 Camera Calibration Utility.xcodeproj/project.pbxproj

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
objects = {
88

99
/* Begin PBXBuildFile section */
10+
4A0720F91E6637FE00084FB6 /* PrefsWindow.xib in Resources */ = {isa = PBXBuildFile; fileRef = 4A0720F81E6637FE00084FB6 /* PrefsWindow.xib */; };
11+
4A0720FC1E663EBA00084FB6 /* PrefsWindowController.m in Sources */ = {isa = PBXBuildFile; fileRef = 4A0720FB1E663EBA00084FB6 /* PrefsWindowController.m */; };
1012
4A5FA0B41DFE138D00795630 /* readtex.c in Sources */ = {isa = PBXBuildFile; fileRef = 4A5FA0B31DFE138D00795630 /* readtex.c */; };
1113
4A5FA0B71DFE13B300795630 /* EdenMessage.c in Sources */ = {isa = PBXBuildFile; fileRef = 4A5FA0B61DFE13B300795630 /* EdenMessage.c */; };
1214
4A5FA0BB1DFE140000795630 /* EdenTime.c in Sources */ = {isa = PBXBuildFile; fileRef = 4A5FA0BA1DFE140000795630 /* EdenTime.c */; };
@@ -88,6 +90,9 @@
8890
/* End PBXCopyFilesBuildPhase section */
8991

9092
/* Begin PBXFileReference section */
93+
4A0720F81E6637FE00084FB6 /* PrefsWindow.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = PrefsWindow.xib; sourceTree = "<group>"; };
94+
4A0720FA1E663EBA00084FB6 /* PrefsWindowController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PrefsWindowController.h; sourceTree = "<group>"; };
95+
4A0720FB1E663EBA00084FB6 /* PrefsWindowController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PrefsWindowController.m; sourceTree = "<group>"; };
9196
4A5FA0B31DFE138D00795630 /* readtex.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = readtex.c; sourceTree = "<group>"; };
9297
4A5FA0B51DFE139F00795630 /* readtex.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = readtex.h; sourceTree = "<group>"; };
9398
4A5FA0B61DFE13B300795630 /* EdenMessage.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = EdenMessage.c; sourceTree = "<group>"; };
@@ -376,6 +381,7 @@
376381
4A9142141DF6453500DF4FEE /* Resources */ = {
377382
isa = PBXGroup;
378383
children = (
384+
4A0720F81E6637FE00084FB6 /* PrefsWindow.xib */,
379385
4A9142091DF6450200DF4FEE /* Assets.xcassets */,
380386
4A91420E1DF6450200DF4FEE /* Info.plist */,
381387
);
@@ -393,6 +399,8 @@
393399
4A9142191DF645A900DF4FEE /* fileUploader.c */,
394400
4A9143511DF6660700DF4FEE /* flow.h */,
395401
4A9143521DF6660700DF4FEE /* flow.c */,
402+
4A0720FA1E663EBA00084FB6 /* PrefsWindowController.h */,
403+
4A0720FB1E663EBA00084FB6 /* PrefsWindowController.m */,
396404
4A9143541DF666E200DF4FEE /* Eden */,
397405
);
398406
name = Source;
@@ -915,6 +923,7 @@
915923
isa = PBXResourcesBuildPhase;
916924
buildActionMask = 2147483647;
917925
files = (
926+
4A0720F91E6637FE00084FB6 /* PrefsWindow.xib in Resources */,
918927
4A91420A1DF6450200DF4FEE /* Assets.xcassets in Resources */,
919928
);
920929
runOnlyForDeploymentPostprocessing = 0;
@@ -949,6 +958,7 @@
949958
4A9143701DF666E200DF4FEE /* glut_bwidth.c in Sources */,
950959
4A91421B1DF645A900DF4FEE /* calc.cpp in Sources */,
951960
4A91436C1DF666E200DF4FEE /* EdenSurfaces.c in Sources */,
961+
4A0720FC1E663EBA00084FB6 /* PrefsWindowController.m in Sources */,
952962
4A91436B1DF666E200DF4FEE /* EdenGLFont.c in Sources */,
953963
);
954964
runOnlyForDeploymentPostprocessing = 0;
@@ -983,7 +993,10 @@
983993
DEBUG_INFORMATION_FORMAT = dwarf;
984994
ENABLE_STRICT_OBJC_MSGSEND = YES;
985995
ENABLE_TESTABILITY = YES;
986-
FRAMEWORK_SEARCH_PATHS = ../depends/macos/Frameworks;
996+
FRAMEWORK_SEARCH_PATHS = (
997+
../depends/macos/Frameworks,
998+
../../artoolkit6/SDK/Frameworks,
999+
);
9871000
GCC_C_LANGUAGE_STANDARD = gnu99;
9881001
GCC_DYNAMIC_NO_PIC = NO;
9891002
GCC_NO_COMMON_BLOCKS = YES;
@@ -1038,7 +1051,10 @@
10381051
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
10391052
ENABLE_NS_ASSERTIONS = NO;
10401053
ENABLE_STRICT_OBJC_MSGSEND = YES;
1041-
FRAMEWORK_SEARCH_PATHS = ../depends/macos/Frameworks;
1054+
FRAMEWORK_SEARCH_PATHS = (
1055+
../depends/macos/Frameworks,
1056+
../../artoolkit6/SDK/Frameworks,
1057+
);
10421058
GCC_C_LANGUAGE_STANDARD = gnu99;
10431059
GCC_NO_COMMON_BLOCKS = YES;
10441060
GCC_PREPROCESSOR_DEFINITIONS = (

macOS/PrefsWindow.xib

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="11762" systemVersion="16D32" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
3+
<dependencies>
4+
<deployment identifier="macosx"/>
5+
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="11762"/>
6+
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
7+
</dependencies>
8+
<objects>
9+
<customObject id="-2" userLabel="File's Owner" customClass="PrefsWindowController">
10+
<connections>
11+
<outlet property="calibrationServerDNSNameOrIPAddress" destination="CeU-9l-p2K" id="iJJ-Ww-MNl"/>
12+
<outlet property="cameraInputPopup" destination="aMP-Am-gla" id="AWV-A1-fhy"/>
13+
<outlet property="showPrefsOnStartup" destination="10P-u0-X5C" id="1qf-WH-mU0"/>
14+
<outlet property="window" destination="QvC-M9-y7g" id="xhk-27-pWa"/>
15+
</connections>
16+
</customObject>
17+
<customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/>
18+
<customObject id="-3" userLabel="Application" customClass="NSObject"/>
19+
<window title="Preferences" allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" oneShot="NO" releasedWhenClosed="NO" animationBehavior="default" id="QvC-M9-y7g">
20+
<windowStyleMask key="styleMask" titled="YES" closable="YES" miniaturizable="YES"/>
21+
<windowPositionMask key="initialPositionMask" leftStrut="YES" rightStrut="YES" topStrut="YES" bottomStrut="YES"/>
22+
<rect key="contentRect" x="196" y="240" width="480" height="270"/>
23+
<rect key="screenRect" x="0.0" y="0.0" width="2560" height="1417"/>
24+
<view key="contentView" wantsLayer="YES" id="EiT-Mj-1SZ">
25+
<rect key="frame" x="0.0" y="0.0" width="480" height="270"/>
26+
<autoresizingMask key="autoresizingMask"/>
27+
<subviews>
28+
<textField verticalHuggingPriority="750" fixedFrame="YES" allowsCharacterPickerTouchBarItem="NO" translatesAutoresizingMaskIntoConstraints="NO" id="CeU-9l-p2K">
29+
<rect key="frame" x="20" y="202" width="243" height="22"/>
30+
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
31+
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" selectable="YES" editable="YES" sendsActionOnEndEditing="YES" state="on" borderStyle="bezel" title="Calibration server name or IP address" placeholderString="omega.artoolworks.com" drawsBackground="YES" id="4cU-vH-g5T">
32+
<font key="font" metaFont="system"/>
33+
<color key="textColor" name="textColor" catalog="System" colorSpace="catalog"/>
34+
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
35+
</textFieldCell>
36+
</textField>
37+
<popUpButton verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="aMP-Am-gla">
38+
<rect key="frame" x="18" y="145" width="248" height="26"/>
39+
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
40+
<popUpButtonCell key="cell" type="push" bezelStyle="rounded" alignment="left" lineBreakMode="truncatingTail" borderStyle="borderAndBezel" imageScaling="proportionallyDown" inset="2" id="cH2-si-7nG">
41+
<behavior key="behavior" lightByBackground="YES" lightByGray="YES"/>
42+
<font key="font" metaFont="menu"/>
43+
<menu key="menu" id="0wG-GD-5aV"/>
44+
</popUpButtonCell>
45+
</popUpButton>
46+
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" allowsCharacterPickerTouchBarItem="NO" translatesAutoresizingMaskIntoConstraints="NO" id="ANx-b9-auz">
47+
<rect key="frame" x="18" y="177" width="245" height="17"/>
48+
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
49+
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="Camera input" id="VII-xJ-dCN">
50+
<font key="font" metaFont="system"/>
51+
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
52+
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
53+
</textFieldCell>
54+
</textField>
55+
<button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="0nN-qx-E1Q">
56+
<rect key="frame" x="375" y="13" width="91" height="32"/>
57+
<constraints>
58+
<constraint firstAttribute="width" constant="79" id="R8P-s3-KQ0"/>
59+
</constraints>
60+
<buttonCell key="cell" type="push" title="OK" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="M9K-6j-BYt">
61+
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
62+
<font key="font" metaFont="system"/>
63+
<string key="keyEquivalent" base64-UTF8="YES">
64+
DQ
65+
</string>
66+
</buttonCell>
67+
<connections>
68+
<action selector="okSelected:" target="-2" id="iht-Gx-MdU"/>
69+
</connections>
70+
</button>
71+
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" allowsCharacterPickerTouchBarItem="NO" translatesAutoresizingMaskIntoConstraints="NO" id="ZFG-1D-LRf">
72+
<rect key="frame" x="20" y="232" width="231" height="17"/>
73+
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
74+
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="Calibration server name or IP address" id="XDh-Pm-b6p">
75+
<font key="font" metaFont="system"/>
76+
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
77+
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
78+
</textFieldCell>
79+
</textField>
80+
<button translatesAutoresizingMaskIntoConstraints="NO" id="10P-u0-X5C">
81+
<rect key="frame" x="241" y="22" width="122" height="18"/>
82+
<buttonCell key="cell" type="check" title="Show on startup" bezelStyle="regularSquare" imagePosition="right" state="on" inset="2" id="fA4-xY-vlY">
83+
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
84+
<font key="font" metaFont="system"/>
85+
</buttonCell>
86+
</button>
87+
</subviews>
88+
<constraints>
89+
<constraint firstItem="0nN-qx-E1Q" firstAttribute="leading" secondItem="10P-u0-X5C" secondAttribute="trailing" constant="20" id="kTJ-Hj-kGE"/>
90+
<constraint firstAttribute="bottom" secondItem="0nN-qx-E1Q" secondAttribute="bottom" constant="20" id="u7D-2T-F0w"/>
91+
<constraint firstAttribute="trailing" secondItem="0nN-qx-E1Q" secondAttribute="trailing" constant="20" id="xud-Mt-fno"/>
92+
<constraint firstItem="10P-u0-X5C" firstAttribute="centerY" secondItem="0nN-qx-E1Q" secondAttribute="centerY" id="zyj-W7-mAE"/>
93+
</constraints>
94+
</view>
95+
<connections>
96+
<outlet property="delegate" destination="-2" id="qmh-q1-8Ho"/>
97+
</connections>
98+
<point key="canvasLocation" x="132" y="162"/>
99+
</window>
100+
</objects>
101+
</document>

macOS/PrefsWindowController.h

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
//
2+
// PrefsWindowController.h
3+
// ARToolKit6 Camera Calibration Utility
4+
//
5+
// Created by Philip Lamb on 1/03/17.
6+
// Copyright © 2017 artoolkit.org. All rights reserved.
7+
//
8+
9+
#ifndef __PrefsWindowController_h__
10+
#define __PrefsWindowController_h__
11+
12+
#if __OBJC__
13+
14+
#import <Cocoa/Cocoa.h>
15+
16+
@interface PrefsWindowController : NSWindowController
17+
{
18+
IBOutlet NSButton *showPrefsOnStartup;
19+
IBOutlet NSTextField *calibrationServerDNSNameOrIPAddress;
20+
IBOutlet NSPopUpButton *cameraInputPopup;
21+
}
22+
- (IBAction)okSelected:(NSButton *)sender;
23+
@end
24+
25+
#endif
26+
27+
#ifdef __cplusplus
28+
extern "C" {
29+
#endif
30+
31+
void *initPreferences(void);
32+
void showPreferences(void *preferences);
33+
34+
int getCameraIndex(void);
35+
36+
37+
#ifdef __cplusplus
38+
}
39+
#endif
40+
#endif // !__PrefsWindowController_h__

0 commit comments

Comments
 (0)