Top Banner
Elastic Image Software LLC Douglass Turner Elastic Image Software tweets: @dugla email: [email protected] Implementing Data Visualization Apps on iOS Devices
110

Implementing Data Visualization Apps on iOS Devices

May 08, 2015

Download

Technology

Douglass Turner
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Implementing Data Visualization Apps on iOS Devices

Elastic Image Software LLC

Douglass TurnerElastic Image Softwaretweets: @duglaemail: [email protected]

Implementing Data Visualization Apps on iOS Devices

Page 2: Implementing Data Visualization Apps on iOS Devices

Elastic Image Software LLC

iOS software development is done using Objective-C an object-oriented superset of C.

It was developed in the spirit of Smalltalk.

2

Page 3: Implementing Data Visualization Apps on iOS Devices

Elastic Image Software LLC

• Objective-C is simple, approachable, lightweight, and pragmatic. No frills.

• Objective-C and C can be intermingled freely.• Think OOP for C hackers and Unix heads.

3

Page 4: Implementing Data Visualization Apps on iOS Devices

Elastic Image Software LLC

• Class: Grouping of data + code. The type of an object.• Instance: A specific copy of a class.• Method: A message that an object can respond to.• Instance variable (ivar): A piece of data belonging to an object

4

Objective-C Supports

Page 5: Implementing Data Visualization Apps on iOS Devices

Elastic Image Software LLC

5

Interface - .h file

@interface className : superclassName

@property(nonatomic, retain) Type *propertyForType;

+(return_type)classMethod;

+(return_type)classMethodWithParam:(paramType) paramName;

-(return_type)instanceMethodWithParam1:(param1Type)param1Name andParam2:(param2Type) param2Name;

@end

Page 6: Implementing Data Visualization Apps on iOS Devices

Elastic Image Software LLC

6

@implementation classname

@synthesize propertyForType;

+(return_type)classMethod { // do stuff}

+(return_type)classMethodWithParam:(paramType) paramName { // do stuff}

-(return_type)instanceMethodWithParam1:(param1Type)param1Name andParam2:(param2Type) param2Name { // do stuff}

@end

Implementation - .m file

Page 7: Implementing Data Visualization Apps on iOS Devices

Elastic Image Software LLC

Apple style tends towards longSelfDocumentingMethodNames.

7

Page 8: Implementing Data Visualization Apps on iOS Devices

Elastic Image Software LLC

8

Instantiationself.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

Property settingself.window.backgroundColor = [UIColor whiteColor];

Message passing[self.window makeKeyAndVisible];

Page 9: Implementing Data Visualization Apps on iOS Devices

Elastic Image Software LLC

9

Objective-C Types

Page 10: Implementing Data Visualization Apps on iOS Devices

Elastic Image Software LLC

10

Dynamically-typed: id whoCaresWhatThisIs;

Statically-typed: Thang* aThang;

Page 11: Implementing Data Visualization Apps on iOS Devices

Elastic Image Software LLC

11

Selectors identify methods by name

@interface Observer : NSObject

- (id)initWithTarget:(id)object action:(SEL)action;@property(nonatomic, strong) id targetObject;@property(nonatomic) SEL targetAction;

@end

Page 12: Implementing Data Visualization Apps on iOS Devices

Elastic Image Software LLC

12

Selectors identify methods by name

observer = [[Observer alloc] initWithTarget:self action:@selector(updateDisplay:)];

Page 13: Implementing Data Visualization Apps on iOS Devices

Elastic Image Software LLC

13

Objective Lifecycle

• Create an instance.• Futz with it (Send messages. Pass it around.)• Discard it.

Page 14: Implementing Data Visualization Apps on iOS Devices

Elastic Image Software LLC

iOS is designed around one foundational pattern: Model View Controller.

Much of iOS development - excluding Model development - involves customization and extension of this pattern.

14

Page 15: Implementing Data Visualization Apps on iOS Devices

Elastic Image Software LLC

15

Controller

Model View

reference reference

reference

Page 16: Implementing Data Visualization Apps on iOS Devices

Elastic Image Software LLC

16

Controller

Model View

Target - Action

Key-value Observingor

Notification

Key-value Observingor

Notification

Page 17: Implementing Data Visualization Apps on iOS Devices

Elastic Image Software LLC

17

iOS has rich support for a loose, flat, decoupled style of programming

• Notification• Target - Action• Key-value Observing (KVO)• Block & Dispatch Queue• Delegation (Protocol)

Page 18: Implementing Data Visualization Apps on iOS Devices

Elastic Image Software LLC

18

Notifications

Page 19: Implementing Data Visualization Apps on iOS Devices

Elastic Image Software LLC

19

[[NSNotificationCenter defaultCenter] postNotificationName:MyNotification object:self];

Notification

Notifier

Page 20: Implementing Data Visualization Apps on iOS Devices

Elastic Image Software LLC

20

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(respondToMyNotification:) name:MyNotification object:nil];

Notification

- (void) respondToMyNotification:(NSNotification *)notification { // do stuff}

Notification respondent

Page 21: Implementing Data Visualization Apps on iOS Devices

Elastic Image Software LLC

21

Target - Action

Page 22: Implementing Data Visualization Apps on iOS Devices

Elastic Image Software LLC

22

Target - Action

Page 23: Implementing Data Visualization Apps on iOS Devices

Elastic Image Software LLC

23

Target - Action

Page 24: Implementing Data Visualization Apps on iOS Devices

Elastic Image Software LLC

24

Target - Action

Page 25: Implementing Data Visualization Apps on iOS Devices

Elastic Image Software LLC

25

Target - Action

@interface Counter : NSObject

@property(nonatomic, strong) NSNumber *count;- (IBAction)trackSlider:(UISlider *)slider;

@end

Page 26: Implementing Data Visualization Apps on iOS Devices

Elastic Image Software LLC

26

Target - Action

@implementation Counter

-(IBAction) trackSlider:(UISlider *)slider; {! self.count = [NSNumber numberWithFloat:slider.value];}

@end

Page 27: Implementing Data Visualization Apps on iOS Devices

Elastic Image Software LLC

27

Target - Action

@class Observer;@class Counter;

@interface EIViewController : UIViewController@property(nonatomic, strong) IBOutlet UILabel *label;@property(nonatomic, strong) Observer *observer;@property(nonatomic, strong) IBOutlet Counter *counter;- (void)updateLabel:(NSNumber *)newValue;@end

Page 28: Implementing Data Visualization Apps on iOS Devices

Elastic Image Software LLC

28

Target - Action

@implementation EIViewController

- (void)viewDidLoad {

self.observer = [[Observer alloc] initWithTarget:self action:@selector(updateLabel:)];

[self.counter addObserver:self.observer forKeyPath:@"count" options:NSKeyValueObservingOptionNew context:NULL];}

-(void) updateLabel:(NSNumber *)newValue {

self.label.text = [NSString stringWithFormat:@"%.2f", [newValue floatValue]];}

@end

Page 29: Implementing Data Visualization Apps on iOS Devices

Elastic Image Software LLC

29

Key-value Observing (KVO)

Page 30: Implementing Data Visualization Apps on iOS Devices

Elastic Image Software LLC

30

Any property is by default “Key-value Compliant” allowing it to be observed.

Page 31: Implementing Data Visualization Apps on iOS Devices

Elastic Image Software LLC

31

Example: HelloSliderGitHub: http://bit.ly/XDxIvp

Page 32: Implementing Data Visualization Apps on iOS Devices

Elastic Image Software LLC

32

Example: HelloSliderGitHub: http://bit.ly/XDxIvp

Page 33: Implementing Data Visualization Apps on iOS Devices

Elastic Image Software LLC

33

Example: HelloSliderGitHub: http://bit.ly/XDxIvp

Page 34: Implementing Data Visualization Apps on iOS Devices

Elastic Image Software LLC

34

Example: HelloSliderGitHub: http://bit.ly/XDxIvp

@interface Counter : NSObject

@property(nonatomic, strong) NSNumber *count;- (IBAction)trackSlider:(UISlider *)slider;

@end

Page 35: Implementing Data Visualization Apps on iOS Devices

Elastic Image Software LLC

35

Example: HelloSliderGitHub: http://bit.ly/XDxIvp

@implementation Counter

-(IBAction) trackSlider:(UISlider *)slider; {! self.count = [NSNumber numberWithFloat:slider.value];}

@end

Page 36: Implementing Data Visualization Apps on iOS Devices

Elastic Image Software LLC

36

@interface Observer : NSObject- (id)initWithTarget:(id)object action:(SEL)action;@property(nonatomic, strong) id targetObject;@property(nonatomic) SEL targetAction;@end

Example: HelloSliderGitHub: http://bit.ly/XDxIvp

Page 37: Implementing Data Visualization Apps on iOS Devices

Elastic Image Software LLC

37

@implementation Observer

- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context { [self.targetObject performSelectorOnMainThread:self.targetAction withObject:[object valueForKeyPath:keyPath] waitUntilDone:NO];

}

@end

Example: HelloSliderGitHub: http://bit.ly/XDxIvp

Page 38: Implementing Data Visualization Apps on iOS Devices

Elastic Image Software LLC

38

Example: HelloSliderGitHub: http://bit.ly/XDxIvp

@implementation EIViewController

- (void)viewDidLoad {

self.observer = [[Observer alloc] initWithTarget:self action:@selector(updateLabel:)];

[self.counter addObserver:self.observer forKeyPath:@"count" options:NSKeyValueObservingOptionNew context:NULL];}

-(void) updateLabel:(NSNumber *)newValue {

self.label.text = [NSString stringWithFormat:@"%.2f", [newValue floatValue]];}

@end

Page 39: Implementing Data Visualization Apps on iOS Devices

Elastic Image Software LLC

39

Blocks & Dispatch Queues

Page 40: Implementing Data Visualization Apps on iOS Devices

Elastic Image Software LLC

40

^{ NSLog(@"Doing something"); }

Blocks & Dispatch Queues

dispatch_queue_t queue = dispatch_get_global_queue(0,0);

dispatch_async(queue, ^{ NSLog(@"Doing something");});

Block

Dispatch Queue

Page 41: Implementing Data Visualization Apps on iOS Devices

Elastic Image Software LLC

41

Blocks & Dispatch Queues

- (void)updateFeaturesWithNotification:(NSNotification *)notification {

dispatch_async([UIApplication sharedIGVAppDelegate].trackControllerQueue, ^{

[self updateFeatures];

dispatch_async(dispatch_get_main_queue(), ^{

[self.coverageTrack setNeedsDisplay]; [self.track setNeedsDisplay]; }); });

}

Page 42: Implementing Data Visualization Apps on iOS Devices

Elastic Image Software LLC

42

Delegation (Protocol)

Page 43: Implementing Data Visualization Apps on iOS Devices

Elastic Image Software LLC

43

A protocol is identical to an interface in Java. A collection of method signatures implemented by the object that “conforms” to the protocol.

The delegate/protocol pattern is ubiquitous throughout iOS.

Delegation (Protocol)

Page 44: Implementing Data Visualization Apps on iOS Devices

Elastic Image Software LLC

44

@interface UITableViewController:UIViewController <UITableViewDelegate, UITableViewDataSource>

UITableViewController inherits from UIViewController and conforms to the UITableViewDelegate and UITableViewDataSource protocols

Delegation (Protocol)

Page 45: Implementing Data Visualization Apps on iOS Devices

Elastic Image Software LLC

45

UITableViewDelegate

@protocol UITableViewDelegate<NSObject, UIScrollViewDelegate>

@optional - (NSIndexPath *)tableView:willSelectRowAtIndexPath:; - (NSIndexPath *)tableView:willDeselectRowAtIndexPath:;

@end

Page 46: Implementing Data Visualization Apps on iOS Devices

Elastic Image Software LLC

46

@protocol UITableViewDataSource<NSObject>

@required- (NSInteger)tableView:numberOfRowsInSection:;

@optional- (NSInteger)numberOfSectionsInTableView:;- (NSArray *)sectionIndexTitlesForTableView:;

@end

UITableViewDataSource

Page 47: Implementing Data Visualization Apps on iOS Devices

Elastic Image Software LLC

47

iOS devices combine mobility, gesture, and a powerful GPU. This makes iOS App development an entirely new form of software development.

Page 48: Implementing Data Visualization Apps on iOS Devices

Elastic Image Software LLC

48

Mobility introduces context as a driver for usage. New app types appear to meet user needs drivenby context.

Page 49: Implementing Data Visualization Apps on iOS Devices

Elastic Image Software LLC

49

Gesture forces a “no interface”, approach to app design and U/X mindset.

Data representation drives interaction and associated affordances.

Page 50: Implementing Data Visualization Apps on iOS Devices

Elastic Image Software LLC

50

GPU. That cute little iPhone in your hand is a graphics processing beast.

It is a GPU device tamed for domestic use. The entire interface is GPU driven.

That is why iOS apps feel the way they do. Light. Effortless. Friction free. Like butter.

Page 51: Implementing Data Visualization Apps on iOS Devices

Elastic Image Software LLC

51

Developers must discard many of their desktop assumptions when developing for iOS

• No mouse• No interface• Minimal keyboard• Arms length interaction• One handed Interaction• Two handed Interaction• Untethered resources

Page 52: Implementing Data Visualization Apps on iOS Devices

Elastic Image Software LLC

52

Demos & Code

Page 53: Implementing Data Visualization Apps on iOS Devices

Elastic Image Software LLC

53

Multi-resolution Image

• CATiledLayer• UIScrollView• Amazon Web Services (S3)

Page 54: Implementing Data Visualization Apps on iOS Devices

Elastic Image Software LLC

54

Multi-resolution Image

• 8k x 8k image resolution. 101MB on disk.• Subsampled 4 successive times• Diced into 256 x 256 tiles• Stored on Amazon S3

Page 55: Implementing Data Visualization Apps on iOS Devices

Elastic Image Software LLC

55

Page 56: Implementing Data Visualization Apps on iOS Devices

Elastic Image Software LLC

56

Page 57: Implementing Data Visualization Apps on iOS Devices

Elastic Image Software LLC

57

Page 58: Implementing Data Visualization Apps on iOS Devices

Elastic Image Software LLC

58

IGV for iPad

• CoreGraphics• Dispatch Queues• UIScrollView

Page 59: Implementing Data Visualization Apps on iOS Devices

Elastic Image Software LLC

59

Page 60: Implementing Data Visualization Apps on iOS Devices

Elastic Image Software LLC

60

Page 61: Implementing Data Visualization Apps on iOS Devices

Elastic Image Software LLC

61

Page 62: Implementing Data Visualization Apps on iOS Devices

Elastic Image Software LLC

62

Page 63: Implementing Data Visualization Apps on iOS Devices

Elastic Image Software LLC

63

Page 64: Implementing Data Visualization Apps on iOS Devices

Elastic Image Software LLC

64

Page 65: Implementing Data Visualization Apps on iOS Devices

Elastic Image Software LLC

65

Page 66: Implementing Data Visualization Apps on iOS Devices

Elastic Image Software LLC

66

Page 67: Implementing Data Visualization Apps on iOS Devices

Elastic Image Software LLC

67

Page 68: Implementing Data Visualization Apps on iOS Devices

Elastic Image Software LLC

68

Page 69: Implementing Data Visualization Apps on iOS Devices

Elastic Image Software LLC

69

Page 70: Implementing Data Visualization Apps on iOS Devices

Elastic Image Software LLC

70

Page 71: Implementing Data Visualization Apps on iOS Devices

Elastic Image Software LLC

71

Page 72: Implementing Data Visualization Apps on iOS Devices

Elastic Image Software LLC

72

The Elastic Image

• OpenGL• GLSL - OpenGL Shading Language• Shader/Gesture plug-ability via plist• UISplitViewController

Page 73: Implementing Data Visualization Apps on iOS Devices

Elastic Image Software LLC

73

Page 74: Implementing Data Visualization Apps on iOS Devices

Elastic Image Software LLC

74

Page 75: Implementing Data Visualization Apps on iOS Devices

Elastic Image Software LLC

75

Page 76: Implementing Data Visualization Apps on iOS Devices

Elastic Image Software LLC

76

Page 77: Implementing Data Visualization Apps on iOS Devices

Elastic Image Software LLC

77

Page 78: Implementing Data Visualization Apps on iOS Devices

Elastic Image Software LLC

78

Page 79: Implementing Data Visualization Apps on iOS Devices

Elastic Image Software LLC

79

Page 80: Implementing Data Visualization Apps on iOS Devices

Elastic Image Software LLC

80

Page 81: Implementing Data Visualization Apps on iOS Devices

Elastic Image Software LLC

81

Page 82: Implementing Data Visualization Apps on iOS Devices

Elastic Image Software LLC

82

Page 83: Implementing Data Visualization Apps on iOS Devices

Elastic Image Software LLC

83

Page 84: Implementing Data Visualization Apps on iOS Devices

Elastic Image Software LLC

84

Page 85: Implementing Data Visualization Apps on iOS Devices

Elastic Image Software LLC

85

Page 86: Implementing Data Visualization Apps on iOS Devices

Elastic Image Software LLC

86

Page 87: Implementing Data Visualization Apps on iOS Devices

Elastic Image Software LLC

87

Page 88: Implementing Data Visualization Apps on iOS Devices

Elastic Image Software LLC

88

self.panGesture = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handlePanGesture:)];[self addGestureRecognizer:self.panGesture];

The Elastic Image

Gestures are fundamental to iOS apps. A gesture is attached to a UIView. Gestures come in different flavors.

self.scaleGesture = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(handleScaleGesture:)];[self addGestureRecognizer:self. scaleGesture];

self.toggleGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleToggleGesture:)];self.toggleGesture.numberOfTapsRequired!! = 1;self.toggleGesture.numberOfTouchesRequired! = 1;[self addGestureRecognizer:self.toggleGesture];

Pan

Pinch

Tap

Page 89: Implementing Data Visualization Apps on iOS Devices

Elastic Image Software LLC

89

The Elastic Image

Photo f/x are implemented in GLSL. The OpenGL Shading Language. Shaders are written in a C-like language and evaluated in a SIMD manner on the entire image in realtime.

Page 90: Implementing Data Visualization Apps on iOS Devices

Elastic Image Software LLC

90

The Elastic Image

varying!vec2 v_st;

uniform sampler2D hero;

void main() {!! gl_FragColor = (heroChannels == 1) ? vec4(texture2D(hero, v_st).a) : texture2D(hero, v_st);!}

varying!vec2 v_st;

uniform sampler2D hero;

void main() {!! gl_FragColor = (heroChannels == 1) ? vec4(texture2D(hero, v_st).a) : texture2D(hero, v_st);!}

TextureMapShader - apply a texture (the photo) to a quad (the rendering surface).

Page 91: Implementing Data Visualization Apps on iOS Devices

Elastic Image Software LLC

91

The Elastic Image

Property lists enable simple specification of a shader gesture and its handler.The Objective-C runtimes enables easy conversion from string to class instance

Page 92: Implementing Data Visualization Apps on iOS Devices

Elastic Image Software LLC

92

- (UIGestureRecognizer *)createGestureWithDictionary:(NSDictionary *)gestureDictionary {

NSString *gestureClassName = [gestureDictionary objectForKey:@"class"]; Class _gesture = NSClassFromString(gestureClassName);

NSString *selectorName = [gestureDictionary objectForKey:@"selector"]; SEL _selector = NSSelectorFromString(selectorName);

UIGestureRecognizer *shaderGesture = [[[_gesture alloc] initWithTarget:self action:_selector] autorelease];

shaderGesture.delegate = self.detailController;

return shaderGesture;}

The Elastic Image

Property lists enable simple specification of a shader gesture and its handler.The Objective-C runtimes enables easy conversion from string to class instance

Page 93: Implementing Data Visualization Apps on iOS Devices

Elastic Image Software LLC

93

• OpenGL• GLSL - OpenGL Shading Language• Proprietary Panorama Engine• UIPopoverController

Beautiful Panoramas

Page 94: Implementing Data Visualization Apps on iOS Devices

Elastic Image Software LLC

94

Page 95: Implementing Data Visualization Apps on iOS Devices

Elastic Image Software LLC

95

Page 96: Implementing Data Visualization Apps on iOS Devices

Elastic Image Software LLC

96

Page 97: Implementing Data Visualization Apps on iOS Devices

Elastic Image Software LLC

97

Page 98: Implementing Data Visualization Apps on iOS Devices

Elastic Image Software LLC

98

Page 99: Implementing Data Visualization Apps on iOS Devices

Elastic Image Software LLC

99

Page 100: Implementing Data Visualization Apps on iOS Devices

Elastic Image Software LLC

100

Page 101: Implementing Data Visualization Apps on iOS Devices

Elastic Image Software LLC

101

• OpenGL• GLSL - OpenGL Shading Language• Proprietary Panorama Engine• 3D Spatial Picking

BMW Interior Panorama

Page 102: Implementing Data Visualization Apps on iOS Devices

Elastic Image Software LLC

102

Page 103: Implementing Data Visualization Apps on iOS Devices

Elastic Image Software LLC

103

Page 104: Implementing Data Visualization Apps on iOS Devices

Elastic Image Software LLC

104

Page 105: Implementing Data Visualization Apps on iOS Devices

Elastic Image Software LLC

105

Page 106: Implementing Data Visualization Apps on iOS Devices

Elastic Image Software LLC

106

Page 107: Implementing Data Visualization Apps on iOS Devices

Elastic Image Software LLC

107

Page 108: Implementing Data Visualization Apps on iOS Devices

Elastic Image Software LLC

108

RadPad

• OpenGL• GLSL - OpenGL Shading Language• Wavelet Image Decompression• UISplitViewController• UIScrollViewController

Page 109: Implementing Data Visualization Apps on iOS Devices

Elastic Image Software LLC

109

Page 110: Implementing Data Visualization Apps on iOS Devices

Elastic Image Software LLC

Thank You

Douglass TurnerElastic Image Softwaretweets: @duglaemail: [email protected]