Commit 5be7b81b authored by Sean McBride's avatar Sean McBride Committed by David E. DeMarle

Various updates/modernizations/improvements to SimpleCocoaVTK example

- Now require newer Xcode and more modern Objective-C dialect.
- Now require building VTK with VTK_CUSTOM_LIBRARY_SUFFIX="",
  which is best practice anyway if using Xcode, so that the CMake-built
  VTK libraries don't constantly change filenames (by having the version number embedded).
- Adjusted Xcode project paths to remove version from filename.
- Added a window controller class, which is more idiomatic.
- The example now uses ARC (automatic reference counting) memory management by default.
- renamed ivars to start with underscore, per Cocoa convention
- added project.xcworkspace to .gitignore
- added usual VTK divider line comments
parent 9c53261f
......@@ -11,3 +11,4 @@ __pycache__/
# Exclude some Xcode stuff.
xcuserdata
project.xcworkspace
......@@ -3,20 +3,19 @@
#import "vtkCocoaGLView.h"
#include "vtkRenderer.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
@interface BasicVTKView : vtkCocoaGLView
{
@private
vtkRenderer* renderer;
}
// Create the vtkRenderer, vtkRenderWindow, and vtkRenderWindowInteractor.
// initializeVTKSupport/cleanUpVTKSupport must be balanced.
- (void)initializeVTKSupport;
// Destroy the vtkRenderer, vtkRenderWindow, and vtkRenderWindowInteractor.
// initializeVTKSupport/cleanUpVTKSupport must be balanced.
- (void)cleanUpVTKSupport;
// Accessors
- (vtkRenderer*)getRenderer;
- (void)setRenderer:(vtkRenderer*)theRenderer;
// Accessors for the vtkRenderer.
- (/*nullable*/ vtkRenderer*)getRenderer;
- (void)setRenderer:(/*nullable*/ vtkRenderer*)theRenderer;
@end
......@@ -6,12 +6,21 @@
#import "vtkCocoaRenderWindowInteractor.h"
#import "vtkCocoaRenderWindow.h"
// Private Interface
@interface BasicVTKView()
{
@private
vtkRenderer* _renderer;
}
@end
@implementation BasicVTKView
// designated initializer
- (id)initWithFrame:(NSRect)frame
// ----------------------------------------------------------------------------
// Designated initializer
- (instancetype)initWithFrame:(NSRect)frameRect
{
self = [super initWithFrame:frame];
self = [super initWithFrame:frameRect];
if (self)
{
// nothing to do... add something if you need to
......@@ -20,13 +29,21 @@
return self;
}
- (void)dealloc
// ----------------------------------------------------------------------------
// Designated initializer
- (/*nullable*/ instancetype)initWithCoder:(NSCoder *)coder
{
[self cleanUpVTKSupport];
[super dealloc];
self = [super initWithCoder:coder];
if (self)
{
// nothing to do... add something if you need to
}
return self;
}
// We are going to over ride the super class here to do some last minute
// ----------------------------------------------------------------------------
// We are going to override the super class here to do some last minute
// setups. We need to do this because if we initialize in the constructor or
// even later, in say an NSDocument's windowControllerDidLoadNib, then
// we will get a warning about "Invalid Drawable" because the OpenGL Context
......@@ -52,9 +69,10 @@
[super drawRect:theRect];
}
// ----------------------------------------------------------------------------
- (void)initializeVTKSupport
{
// The usual vtk object creation
// The usual vtk object creation.
vtkRenderer* ren = vtkRenderer::New();
vtkRenderWindow* renWin = vtkRenderWindow::New();
vtkRenderWindowInteractor* renWinInt = vtkRenderWindowInteractor::New();
......@@ -70,8 +88,8 @@
// default behaviour) we tell vtk that they exist already.
// The APIs names are a bit misleading, due to the cross
// platform nature of vtk, but this usage is correct.
cocoaRenWin->SetRootWindow([self window]);
cocoaRenWin->SetWindowId(self);
cocoaRenWin->SetRootWindow((__bridge void*)[self window]);
cocoaRenWin->SetWindowId((__bridge void*)self);
// The usual vtk connections
cocoaRenWin->AddRenderer(ren);
......@@ -82,11 +100,12 @@
// accessor if you ever need it.
[self setVTKRenderWindow:cocoaRenWin];
// Likewise, BasicVTKView keeps track of the renderer
// Likewise, BasicVTKView keeps track of the renderer.
[self setRenderer:ren];
}
}
// ----------------------------------------------------------------------------
- (void)cleanUpVTKSupport
{
vtkRenderer* ren = [self getRenderer];
......@@ -105,21 +124,24 @@
{
renWinInt->Delete();
}
[self setRenderer:NULL];
[self setVTKRenderWindow:NULL];
[self setRenderer:nil];
[self setVTKRenderWindow:nil];
// There is no setter accessor for the render window
// interactor, that's ok.
}
- (vtkRenderer*)getRenderer
// ----------------------------------------------------------------------------
- (/*nullable*/ vtkRenderer*)getRenderer
{
return renderer;
return _renderer;
}
- (void)setRenderer:(vtkRenderer*)theRenderer
// ----------------------------------------------------------------------------
- (void)setRenderer:(/*nullable*/ vtkRenderer*)theRenderer
{
renderer = theRenderer;
_renderer = theRenderer;
}
@end
......@@ -3,7 +3,7 @@
#-- All rights reserved.
#-- BSD License: http://www.opensource.org/licenses/bsd-license.html
#--////////////////////////////////////////////////////////////////////////////
CMAKE_MINIMUM_REQUIRED(VERSION 2.8.5 FATAL_ERROR)
CMAKE_MINIMUM_REQUIRED(VERSION 2.8.12 FATAL_ERROR)
if(POLICY CMP0025)
cmake_policy(SET CMP0025 NEW) # CMake 3.0
endif()
......@@ -28,18 +28,27 @@ set (SimpleCocoaVTK_SRCS
${SimpleCocoaVTK_SOURCE_DIR}/main.mm
${SimpleCocoaVTK_SOURCE_DIR}/BasicVTKView.mm
${SimpleCocoaVTK_SOURCE_DIR}/MyDocument.mm
${SimpleCocoaVTK_SOURCE_DIR}/MyWindowController.mm
)
# Build all Objective-C as ARC.
set_source_files_properties(main.mm
BasicVTKView.mm
MyDocument.mm
MyWindowController.mm
PROPERTIES COMPILE_FLAGS "-fobjc-arc")
# The Headers
set (SimpleCocoaVTK_HDRS
${SimpleCocoaVTK_SOURCE_DIR}/BasicVTKView.h
${SimpleCocoaVTK_SOURCE_DIR}/MyDocument.h
${SimpleCocoaVTK_SOURCE_DIR}/MyWindowController.h
)
# these are the OS X Interface Builder Files
set (SimpleCocoaVTK_XIBS
MainMenu
MyDocument
MyWindow
)
# Set the OS X Bundle specific CMake variables which will be used to populate the plist for
......@@ -56,7 +65,7 @@ add_executable(SimpleCocoaVTK MACOSX_BUNDLE ${SimpleCocoaVTK_SRCS} ${SimpleCocoa
# Probably a better way to set the framework link libraries.
target_link_libraries(SimpleCocoaVTK "-framework Cocoa -framework OpenGL"
vtkRenderingOpenGL vtkInteractionStyle )
vtkRenderingOpenGL2 vtkInteractionStyle vtkRenderingFreeType vtkFiltersSources vtkRenderingGL2PSOpenGL2 )
# Set a custom plist file for the app bundle
set_target_properties(SimpleCocoaVTK PROPERTIES MACOSX_BUNDLE_INFO_PLIST ${SimpleCocoaVTK_SOURCE_DIR}/Info-CMake.plist)
......
{\rtf1\ansi\ansicpg1252\cocoartf1404\cocoasubrtf340
{\rtf1\ansi\ansicpg1252\cocoartf1404\cocoasubrtf470
\cocoascreenfonts1{\fonttbl\f0\fswiss\fcharset0 Helvetica;}
{\colortbl;\red255\green255\blue255;}
\margl1440\margr1440\vieww21440\viewh21120\viewkind0
\pard\tx566\tx1133\tx1700\tx2267\tx2834\tx3401\tx3968\tx4535\tx5102\tx5669\tx6236\tx6803\tx7380\tx7940\tx8520\pardirnatural\partightenfactor0
\f0\fs38 \cf0 SimpleCocoaVTK 2.0\
2016-02-08\
\f0\fs38 \cf0 SimpleCocoaVTK 3.0\
2016-09-12\
by: Sean McBride and Mike Jackson\
\fs34 \
\ul Pre-Requisites:\
\ulnone \
1) you need Mac OS X 10.7 and Xcode 4.x or later installed on your Mac.\
2) you need CMake 2.8.10 or later.\
3) you need to know the basics of Xcode, CMake, VTK, and Cocoa already.\
4) you have to build VTK 7.1 separately. The Xcode project expects VTK to be built with certain options, see below.\
1) you need Mac OS X 10.9.5 or later\
2) you need Xcode 6.2 or later.\
3) you need CMake 2.8.12 or later.\
4) you need to know the basics of Xcode, CMake, VTK, and Cocoa already.\
5) you have to build VTK separately. The Xcode project expects VTK to be built with certain options, see below.\
\
\ul Purpose of Example:\
\ulnone \
This simple example is intended to show how to use VTK in a Mac-only Xcode-based Cocoa application. VTK's vtkCocoaGLView is a subclass of NSView and you can use it like pretty much any other NSView!\
\
This example is an NSDocument-based application, and has two independent vtkCocoaGLViews in the document's NIB. One shows a cone, and one shows a cylinder.\
This example is an NSDocument-based application with a single window controller. The window has two independent vtkCocoaGLViews in the XIB. One shows a cone, and one shows a cylinder.\
\
See the screenshot (in the same folder as this file) to see what the app looks like.\
\
......@@ -29,6 +30,7 @@ See the screenshot (in the same folder as this file) to see what the app looks l
First, you need to build VTK. SimpleCocoaVTK requires that you build VTK with the following non-default options:\
BUILD_SHARED_LIBS OFF \
CMAKE_BUILD_TYPE Debug \
VTK_CUSTOM_LIBRARY_SUFFIX <empty string>\
\
It is recommended to also use these options, and you should synchronize your choices with the SimpleCocoaVTK.xcconfig file: CMAKE_OSX_ARCHITECTURES (as desired)\
CMAKE_OSX_SYSROOT (as desired)\
......@@ -56,6 +58,16 @@ If you have any problems, please post to the vtkusers mailing list.\
\ulnone \
\pard\tx566\tx1133\tx1700\tx2267\tx2834\tx3401\tx3968\tx4535\tx5102\tx5669\tx6236\tx6803\tx7380\tx7940\tx8520\pardirnatural\partightenfactor0
\i \cf0 Changes in 3.0 (since 2.0)\
\pard\tx566\tx1133\tx1700\tx2267\tx2834\tx3401\tx3968\tx4535\tx5102\tx5669\tx6236\tx6803\tx7380\tx7940\tx8520\pardirnatural\partightenfactor0
\i0 \cf0 - Now require newer Xcode and more modern Objective-C dialect.\
- Now require building VTK with VTK_CUSTOM_LIBRARY_SUFFIX=<empty string>, which is best practice anyway if using Xcode, so that the CMake-built VTK libraries don't constantly change filenames (by having the version number embedded).\
- Added a window controller class, which is more idiomatic.\
- The example now uses ARC (automatic reference counting) memory management by default. (This doesn't mean VTK needs to compiled as ARC, indeed, it cannot yet be.)\
\
\pard\tx566\tx1133\tx1700\tx2267\tx2834\tx3401\tx3968\tx4535\tx5102\tx5669\tx6236\tx6803\tx7380\tx7940\tx8520\pardirnatural\partightenfactor0
\i \cf0 Changes in 2.0 (since 1.9)\
\pard\tx566\tx1133\tx1700\tx2267\tx2834\tx3401\tx3968\tx4535\tx5102\tx5669\tx6236\tx6803\tx7380\tx7940\tx8520\pardirnatural\partightenfactor0
......
This diff is collapsed.
#import <Cocoa/Cocoa.h>
@class BasicVTKView;
@interface MyDocument : NSDocument
{
IBOutlet BasicVTKView* leftVTKView;
IBOutlet BasicVTKView* rightVTKView;
}
@end
#import "MyDocument.h"
#import "BasicVTKView.h"
#import "vtkInteractorStyleSwitch.h"
#import "vtkCocoaRenderWindowInteractor.h"
#import "vtkConeSource.h"
#import "vtkCylinderSource.h"
#import "vtkPolyDataMapper.h"
#import "vtkSmartPointer.h"
#import "vtkDebugLeaks.h"
#import "MyWindowController.h"
@implementation MyDocument
- (void)setupLeftVTKView
{
[leftVTKView initializeVTKSupport];
// 'smart pointers' are used because they are very similiar to creating auto-realeased objects in Cocoa.
// Personal Taste Section. I like to use a trackball interactor
vtkSmartPointer<vtkInteractorStyleSwitch> intStyle = vtkSmartPointer<vtkInteractorStyleSwitch>::New();
intStyle->SetCurrentStyleToTrackballCamera();
[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);
[leftVTKView getRenderer]->AddActor(coneActor);
// Tell the system that the view needs to be redrawn
[leftVTKView setNeedsDisplay:YES];
}
- (void)setupRightVTKView
{
[rightVTKView initializeVTKSupport];
// 'smart pointers' are used because they are very similiar to creating auto-realeased objects in Cocoa.
// Personal Taste Section. I like to use a trackball interactor
vtkSmartPointer<vtkInteractorStyleSwitch> intStyle = vtkSmartPointer<vtkInteractorStyleSwitch>::New();
intStyle->SetCurrentStyleToTrackballCamera();
[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);
[rightVTKView getRenderer]->AddActor(cylinderActor);
// Tell the system that the view needs to be redrawn
[rightVTKView setNeedsDisplay:YES];
}
#pragma mark -
- (id)init
{
self = [super init];
if (self != nil)
{
// Add your subclass-specific initialization here.
// If an error occurs here, send a [self release] message and return nil.
}
return self;
}
- (void)close
// ----------------------------------------------------------------------------
- (void)makeWindowControllers
{
[super close];
// Releases memory allocated in initializeVTKSupport.
// In a way, calling these is pointless since the application is quitting anyway.
[leftVTKView cleanUpVTKSupport];
[rightVTKView cleanUpVTKSupport];
// If you have built vtk with VTK_DEBUG_LEAKS on then this method will print out any leaks
// that exist. The sample has been careful to cleanup after itself, so there should be no leaks.
vtkDebugLeaks::PrintCurrentLeaks();
// Create the window controller and keep a reference to it.
MyWindowController* newWindowController = [[MyWindowController alloc] init];
[newWindowController setShouldCloseDocument:YES];
[self addWindowController:newWindowController];
}
- (NSString *)windowNibName
// ----------------------------------------------------------------------------
- (/*nullable*/ NSData *)dataOfType:(NSString *)typeName
error:(NSError **)outError
{
// Override returning the nib file name of the document
// If you need to use a subclass of NSWindowController or if your document supports multiple NSWindowControllers, you should remove this method and override -makeWindowControllers instead.
return @"MyDocument";
}
- (void)windowControllerDidLoadNib:(NSWindowController *)windowController
{
[super windowControllerDidLoadNib:windowController];
// vtk stuff
[self setupLeftVTKView];
[self setupRightVTKView];
}
- (NSData *)dataRepresentationOfType:(NSString *)aType
{
// Insert code here to write your document from the given data. You can also choose to override -fileWrapperRepresentationOfType: or -writeToFile:ofType: instead.
// For applications targeted for Tiger or later systems, you should use the new Tiger API -dataOfType:error:. In this case you can also choose to override -writeToURL:ofType:error:, -fileWrapperOfType:error:, or -writeToURL:ofType:forSaveOperation:originalContentsURL:error: instead.
return nil;
}
- (BOOL)loadDataRepresentation:(NSData *)data ofType:(NSString *)aType
// ----------------------------------------------------------------------------
- (BOOL)readFromData:(NSData *)data
ofType:(NSString *)typeName
error:(NSError **)outError
{
// Insert code here to read your document from the given data. You can also choose to override -loadFileWrapperRepresentation:ofType: or -readFromFile:ofType: instead.
// For applications targeted for Tiger or later systems, you should use the new Tiger API readFromData:ofType:error:. In this case you can also choose to override -readFromURL:ofType:error: or -readFromFileWrapper:ofType:error: instead.
return YES;
}
......
This diff is collapsed.
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="10117" systemVersion="15G31" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" customObjectInstantitationMethod="direct">
<dependencies>
<deployment version="1080" identifier="macosx"/>
<development version="5100" identifier="xcode"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="10117"/>
</dependencies>
<objects>
<customObject id="-2" userLabel="File's Owner" customClass="MyWindowController">
<connections>
<outlet property="leftVTKView" destination="21" id="27"/>
<outlet property="rightVTKView" destination="24" id="28"/>
<outlet property="window" destination="5" id="18"/>
</connections>
</customObject>
<customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/>
<customObject id="-3" userLabel="Application"/>
<window title="SimpleCocoaVTK" allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" restorable="NO" releasedWhenClosed="NO" visibleAtLaunch="NO" animationBehavior="default" id="5" userLabel="Window">
<windowStyleMask key="styleMask" titled="YES" closable="YES" miniaturizable="YES" resizable="YES"/>
<windowPositionMask key="initialPositionMask" leftStrut="YES" rightStrut="YES" topStrut="YES" bottomStrut="YES"/>
<rect key="contentRect" x="403" y="523" width="982" height="449"/>
<rect key="screenRect" x="0.0" y="0.0" width="1920" height="1177"/>
<value key="minSize" type="size" width="982" height="449"/>
<view key="contentView" id="6">
<rect key="frame" x="0.0" y="0.0" width="982" height="449"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<customView id="21" customClass="BasicVTKView">
<rect key="frame" x="20" y="56" width="467" height="373"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
</customView>
<customView id="24" customClass="BasicVTKView">
<rect key="frame" x="495" y="56" width="467" height="373"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
</customView>
<button verticalHuggingPriority="750" id="Vzv-UY-pTE">
<rect key="frame" x="190" y="13" width="126" height="32"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<buttonCell key="cell" type="push" title="Do Something" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="1Tc-O9-bZ7">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="system"/>
</buttonCell>
<connections>
<action selector="handleLeftButton:" target="-2" id="Vb6-Zg-kaA"/>
</connections>
</button>
<button verticalHuggingPriority="750" id="XQh-Me-qZF">
<rect key="frame" x="665" y="13" width="126" height="32"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<buttonCell key="cell" type="push" title="Do Something" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="Kik-n3-57d">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="system"/>
</buttonCell>
<connections>
<action selector="handleRightButton:" target="-2" id="fM7-iW-HGc"/>
</connections>
</button>
</subviews>
</view>
<connections>
<outlet property="delegate" destination="-2" id="17"/>
</connections>
<point key="canvasLocation" x="520" y="451.5"/>
</window>
</objects>
</document>
#import <Cocoa/Cocoa.h>
@interface MyWindowController : NSWindowController
// Designated initializer
- (instancetype)init /*NS_DESIGNATED_INITIALIZER*/;
@end
#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
......@@ -17,3 +17,6 @@ PRODUCT_NAME = SimpleCocoaVTK
// Use the source trees to find the VTK libs and headers.
HEADER_SEARCH_PATHS = $(vtk-debug-include)
LIBRARY_SEARCH_PATHS = $(vtk-debug-lib)
// Use ARC memory management.
CLANG_ENABLE_OBJC_ARC = YES
#import <Cocoa/Cocoa.h>
// ----------------------------------------------------------------------------
int main(int argc, char *argv[])
{
return NSApplicationMain(argc, (const char **) argv);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment