File: MyWindowController.mm

package info (click to toggle)
vtk7 7.1.1%2Bdfsg2-8
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 127,396 kB
  • sloc: cpp: 1,539,584; ansic: 124,382; python: 78,038; tcl: 47,013; xml: 8,142; yacc: 5,040; java: 4,439; perl: 3,132; lex: 1,926; sh: 1,500; makefile: 126; objc: 83
file content (132 lines) | stat: -rw-r--r-- 4,349 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#import "MyWindowController.h"

#import "BasicVTKView.h"

#import "vtkInteractorStyleSwitch.h"
#import "vtkCocoaRenderWindowInteractor.h"
#import "vtkConeSource.h"
#import "vtkCylinderSource.h"
#import "vtkPolyDataMapper.h"
#import "vtkSmartPointer.h"

// Private Interface
@interface MyWindowController()
@property (readwrite, weak, nonatomic) IBOutlet BasicVTKView* leftVTKView;
@property (readwrite, weak, nonatomic) IBOutlet BasicVTKView* rightVTKView;
@end

@implementation MyWindowController

// ----------------------------------------------------------------------------
- (void)setupLeftVTKView
{
  [[self leftVTKView] initializeVTKSupport];

  // 'smart pointers' are used because they are very similiar to reference counting in Cocoa.

  // Personal Taste Section. I like to use a trackball interactor
  vtkSmartPointer<vtkInteractorStyleSwitch> intStyle = vtkSmartPointer<vtkInteractorStyleSwitch>::New();
  intStyle->SetCurrentStyleToTrackballCamera();
  [[self leftVTKView] getInteractor]->SetInteractorStyle(intStyle);

  // Create a cone, see the "VTK User's Guide" for details
  vtkSmartPointer<vtkConeSource> cone = vtkSmartPointer<vtkConeSource>::New();
  cone->SetHeight(3.0);
  cone->SetRadius(1.0);
  cone->SetResolution(100);

  vtkSmartPointer<vtkPolyDataMapper> coneMapper = vtkSmartPointer<vtkPolyDataMapper>::New();
  coneMapper->SetInputConnection(cone->GetOutputPort());

  vtkSmartPointer<vtkActor> coneActor = vtkSmartPointer<vtkActor>::New();
  coneActor->SetMapper(coneMapper);

  [[self leftVTKView] getRenderer]->AddActor(coneActor);

  // Tell the system that the view needs to be redrawn
  [[self leftVTKView] setNeedsDisplay:YES];
}

// ----------------------------------------------------------------------------
- (void)setupRightVTKView
{
  [[self rightVTKView] initializeVTKSupport];

  // 'smart pointers' are used because they are very similiar to reference counting in Cocoa.

  // Personal Taste Section. I like to use a trackball interactor
  vtkSmartPointer<vtkInteractorStyleSwitch> intStyle = vtkSmartPointer<vtkInteractorStyleSwitch>::New();
  intStyle->SetCurrentStyleToTrackballCamera();
  [[self rightVTKView] getInteractor]->SetInteractorStyle(intStyle);

  // Create a cyclinder, see the "VTK User's Guide" for details
  vtkSmartPointer<vtkCylinderSource> cylinder = vtkSmartPointer<vtkCylinderSource>::New();
  cylinder->SetResolution(100);

  vtkSmartPointer<vtkPolyDataMapper> cylinderMapper = vtkSmartPointer<vtkPolyDataMapper>::New();
  cylinderMapper->SetInputConnection(cylinder->GetOutputPort());

  vtkSmartPointer<vtkActor> cylinderActor = vtkSmartPointer<vtkActor>::New();
  cylinderActor->SetMapper(cylinderMapper);

  [[self rightVTKView] getRenderer]->AddActor(cylinderActor);

  // Tell the system that the view needs to be redrawn
  [[self rightVTKView] setNeedsDisplay:YES];
}

#pragma mark -

// ----------------------------------------------------------------------------
// Designated initializer
- (instancetype)init
{
  // Call the superclass' designated initializer, giving it the name of the nib file.
  self = [super initWithWindowNibName:@"MyWindow"];

  return self;
}

// ----------------------------------------------------------------------------
// Called once when the window is loaded.
- (void)windowDidLoad
{
  // vtk stuff
  [self setupLeftVTKView];
  [self setupRightVTKView];
}

// ----------------------------------------------------------------------------
// Called once when the window is closed.
- (void)windowWillClose:(NSNotification *)inNotification
{
  // Releases memory allocated in initializeVTKSupport.
  [[self leftVTKView] cleanUpVTKSupport];
  [[self rightVTKView] cleanUpVTKSupport];
}

#pragma mark -

// ----------------------------------------------------------------------------
- (IBAction)handleLeftButton:(id)sender
{
  // Do anything you want with the left view.
  NSBeep();

  // Here we just clean it up and remove it
  [[self leftVTKView] cleanUpVTKSupport];
  [[self leftVTKView] removeFromSuperview];
}

// ----------------------------------------------------------------------------
- (IBAction)handleRightButton:(id)sender
{
  // Do anything you want with the left view.
  NSBeep();

  // Here we just clean it up and remove it
  [[self rightVTKView] cleanUpVTKSupport];
  [[self rightVTKView] removeFromSuperview];
}

@end