Commit 9206fc3d authored by Ken Martin's avatar Ken Martin Committed by Kitware Robot

Merge topic 'planeview'

f5a0c4e3 updated to avoid constraint warning
de345070 ios improvements and new example
4c9fe5c4 ios improvements and new example
Acked-by: Kitware Robot's avatarKitware Robot <kwrobot@kitware.com>
Reviewed-by: Berk Geveci's avatarBerk Geveci <berk.geveci@kitware.com>
Merge-request: !1221
parents 92fc99dc f5a0c4e3
......@@ -82,7 +82,17 @@ mark_as_advanced(
# expose some module options
option(Module_vtkRenderingOpenGL2 "Include Polygonal Rendering Support" ON)
option(Module_vtkInteractionWidgets "Include INteractionWidgets module" OFF)
option(Module_vtkInteractionWidgets "Include InteractionWidgets module" OFF)
option(Module_vtkIOXML "Include IO/XML Module" OFF)
option(Module_vtkFiltersModeling "Turn on or off this module" OFF)
option(Module_vtkFiltersSources "Turn on or off this module" OFF)
option(Module_vtkIOGeometry "Turn on or off this module" OFF)
option(Module_vtkIOLegacy "Turn on or off this module" OFF)
option(Module_vtkIOImage "Turn on or off this module" OFF)
option(Module_vtkIOPLY "Turn on or off this module" OFF)
option(Module_vtkIOInfovis "Turn on or off this module" OFF)
option(Module_vtkRenderingFreeType "Turn on or off this module" OFF)
# add volume rendering option for ES 3.0
if (OPENGL_ES_VERSION STREQUAL "3.0" AND Module_vtkRenderingOpenGL2)
......@@ -105,21 +115,16 @@ set(ios_cmake_flags
-DVTK_Group_Qt:BOOL=OFF
-DVTK_Group_Tk:BOOL=OFF
-DVTK_Group_Web:BOOL=OFF
# -DModule_vtkFiltersCore:BOOL=ON
# -DModule_vtkFiltersModeling:BOOL=ON
# -DModule_vtkFiltersSources:BOOL=ON
# -DModule_vtkFiltersGeometry:BOOL=ON
# -DModule_vtkIOGeometry:BOOL=ON
# -DModule_vtkIOLegacy:BOOL=ON
# -DModule_vtkIOImage:BOOL=ON
# -DModule_vtkIOPLY:BOOL=ON
# -DModule_vtkIOInfovis:BOOL=ON
# -DModule_vtkImagingCore:BOOL=ON
# -DModule_vtkInteractionStyle:BOOL=ON
# -DModule_vtkParallelCore:BOOL=ON
# -DModule_vtkRenderingFreeType:BOOL=OFF
-DModule_vtkRenderingOpenGL2:BOOL=${Module_vtkRenderingOpenGL2}
-DModule_vtkInteractionWidgets:BOOL=${Module_vtkInteractionWidgets}
-DModule_vtkFiltersModeling:BOOL=${Module_vtkFiltersModeling}
-DModule_vtkFiltersSources:BOOL=${Module_vtkFiltersSources}
-DModule_vtkIOGeometry:BOOL=${Module_vtkIOGeometry}
-DModule_vtkIOLegacy:BOOL=${Module_vtkIOLegacy}
-DModule_vtkIOImage:BOOL=${Module_vtkIOImage}
-DModule_vtkIOPLY:BOOL=${Module_vtkIOPLY}
-DModule_vtkIOInfovis:BOOL=${Module_vtkIOInfovis}
-DModule_vtkRenderingFreeType:BOOL=${Module_vtkRenderingFreeType}
)
if (Module_vtkRenderingOpenGL2)
......@@ -150,6 +155,17 @@ macro(crosscompile target toolchain_file archs)
-DCMAKE_INSTALL_PREFIX:PATH=${INSTALL_DIR}/${target}
${ios_cmake_flags}
)
#
# add an INSTALL_ALLWAYS since we want it and cmake lacks it
#
ExternalProject_Get_Property(${target} binary_dir)
_ep_get_build_command(${target} INSTALL cmd)
ExternalProject_Add_Step(${target} always-install
COMMAND ${cmd}
WORKING_DIRECTORY ${binary_dir}
DEPENDEES build
ALWAYS 1
)
endmacro()
crosscompile(vtk-ios-simulator
......
......@@ -312,7 +312,19 @@
_vtk_add_event(WindowIsDirectEvent)\
_vtk_add_event(UncheckedPropertyModifiedEvent)\
_vtk_add_event(UpdateShaderEvent)\
_vtk_add_event(MessageEvent)
_vtk_add_event(MessageEvent)\
_vtk_add_event(StartPinchEvent)\
_vtk_add_event(PinchEvent)\
_vtk_add_event(EndPinchEvent)\
_vtk_add_event(StartRotateEvent)\
_vtk_add_event(RotateEvent)\
_vtk_add_event(EndRotateEvent)\
_vtk_add_event(StartPanEvent)\
_vtk_add_event(PanEvent)\
_vtk_add_event(EndPanEvent)\
_vtk_add_event(TapEvent)\
_vtk_add_event(LongTapEvent)\
_vtk_add_event(SwipeEvent)
#define vtkEventDeclarationMacro(_enum_name)\
enum _enum_name{\
......
# copy the example to the binary tree where they can be built manually using xcode
if (TRUE)
add_custom_target(iOS-examples-rm ALL
COMMAND ${CMAKE_COMMAND} -E remove_directory
"${CMAKE_CURRENT_BINARY_DIR}/GLPaint"
COMMAND ${CMAKE_COMMAND} -E remove_directory
"${CMAKE_CURRENT_BINARY_DIR}/Surfaces")
add_custom_target(iOS-examples-rm ALL
COMMAND ${CMAKE_COMMAND} -E remove_directory
"${CMAKE_CURRENT_BINARY_DIR}/GLPaint"
COMMAND ${CMAKE_COMMAND} -E remove_directory
"${CMAKE_CURRENT_BINARY_DIR}/Surfaces"
COMMAND ${CMAKE_COMMAND} -E remove_directory
"${CMAKE_CURRENT_BINARY_DIR}/VolumeRender"
COMMAND ${CMAKE_COMMAND} -E remove_directory
"${CMAKE_CURRENT_BINARY_DIR}/PlaneView")
add_custom_target(iOS-examples-copy ALL
COMMAND ${CMAKE_COMMAND} -E copy_directory
"${CMAKE_CURRENT_SOURCE_DIR}/GLPaint"
"${CMAKE_CURRENT_BINARY_DIR}/GLPaint"
COMMAND ${CMAKE_COMMAND} -E copy_directory
"${CMAKE_CURRENT_SOURCE_DIR}/Surfaces"
"${CMAKE_CURRENT_BINARY_DIR}/Surfaces")
add_custom_target(iOS-examples-copy ALL
COMMAND ${CMAKE_COMMAND} -E copy_directory
"${CMAKE_CURRENT_SOURCE_DIR}/GLPaint"
"${CMAKE_CURRENT_BINARY_DIR}/GLPaint"
COMMAND ${CMAKE_COMMAND} -E copy_directory
"${CMAKE_CURRENT_SOURCE_DIR}/Surfaces"
"${CMAKE_CURRENT_BINARY_DIR}/Surfaces"
COMMAND ${CMAKE_COMMAND} -E copy_directory
"${CMAKE_CURRENT_SOURCE_DIR}/VolumeRender"
"${CMAKE_CURRENT_BINARY_DIR}/VolumeRender"
COMMAND ${CMAKE_COMMAND} -E copy_directory
"${CMAKE_CURRENT_SOURCE_DIR}/PlaneView"
"${CMAKE_CURRENT_BINARY_DIR}/PlaneView")
add_dependencies(iOS-examples-copy iOS-examples-rm)
else ()
add_subdirectory(MaceVTK/MaceVTK)
add_custom_target(iOS-examples-copy ALL
COMMAND ${CMAKE_COMMAND} -E copy_directory
"${CMAKE_CURRENT_SOURCE_DIR}/MaceVTK"
"${CMAKE_CURRENT_BINARY_DIR}/MaceVTK")
endif ()
add_dependencies(iOS-examples-copy iOS-examples-rm)
/*=========================================================================
Program: Visualization Toolkit
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
#import <UIKit/UIKit.h>
#import <GLKit/GLKit.h>
@interface MyGLKViewController : GLKViewController
@property (nonatomic, strong) UIWindow *window;
@end
/*=========================================================================
Program: Visualization Toolkit
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
#import "MyGLKViewController.h"
@interface MyGLKViewController () {
vesKiwiViewerApp::Ptr mKiwiApp;
MyGestureHandler* mGestureHandler;
}
@property (strong, nonatomic) EAGLContext *context;
- (void)tearDownGL;
@end
@implementation MyGLKViewController
- (void)viewDidLoad
{
[super viewDidLoad];
self.context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2];
if (!self.context) {
NSLog(@"Failed to create ES context");
}
GLKView *view = (GLKView *)self.view;
view.context = self.context;
view.drawableDepthFormat = GLKViewDrawableDepthFormat24;
view.drawableMultisample = GLKViewDrawableMultisample4X;
[self initializeKiwiApp];
[self initializeGestureHandler];
}
-(void) initializeKiwiApp
{
[EAGLContext setCurrentContext:self.context];
std::string dataset = [[[NSBundle mainBundle] pathForResource:@"teapot" ofType:@"vtp"] UTF8String];
self->mKiwiApp = vesKiwiViewerApp::Ptr(new vesKiwiViewerApp);
self->mKiwiApp->initGL();
[self resizeView];
self->mKiwiApp->loadDataset(dataset);
self->mKiwiApp->resetView();
}
-(void) initializeGestureHandler
{
self->mGestureHandler = [[MyGestureHandler alloc] init];
self->mGestureHandler.view = self.view;
self->mGestureHandler.kiwiApp = self->mKiwiApp;
[self->mGestureHandler createGestureRecognizers];
}
- (void)dealloc
{
[self tearDownGL];
if ([EAGLContext currentContext] == self.context) {
[EAGLContext setCurrentContext:nil];
}
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
if ([self isViewLoaded] && ([[self view] window] == nil)) {
self.view = nil;
[self tearDownGL];
if ([EAGLContext currentContext] == self.context) {
[EAGLContext setCurrentContext:nil];
}
self.context = nil;
}
// Dispose of any resources that can be recreated.
}
- (void)tearDownGL
{
[EAGLContext setCurrentContext:self.context];
// free GL resources
// ...
}
-(void) resizeView
{
double scale = self.view.contentScaleFactor;
self->mKiwiApp->resizeView(self.view.bounds.size.width*scale, self.view.bounds.size.height*scale);
}
- (void)viewWillLayoutSubviews
{
[self resizeView];
}
- (void)glkView:(GLKView *)view drawInRect:(CGRect)rect
{
if (self->mKiwiApp && !self.paused) {
self->mKiwiApp->render();
}
}
@end
/*=========================================================================
Program: Visualization Toolkit
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
#import <UIKit/UIKit.h>
#import <GLKit/GLKit.h>
// Note: This file should be includable by both pure Objective-C and Objective-C++ source files.
// To achieve this, we use the neat technique below:
#ifdef __cplusplus
// Forward declarations
class vtkIOSRenderWindow;
class vtkIOSRenderWindowInteractor;
// Type declarations
typedef vtkIOSRenderWindow *vtkIOSRenderWindowRef;
typedef vtkIOSRenderWindowInteractor *vtkIOSRenderWindowInteractorRef;
#else
// Type declarations
typedef void *vtkIOSRenderWindowRef;
typedef void *vtkIOSRenderWindowInteractorRef;
#endif
@interface MyGLKViewController : GLKViewController
{
@private
vtkIOSRenderWindowRef _myVTKRenderWindow;
}
@property (nonatomic, strong) UIWindow *window;
- (vtkIOSRenderWindowRef)getVTKRenderWindow;
- (void)setVTKRenderWindow:(vtkIOSRenderWindowRef)theVTKRenderWindow;
- (vtkIOSRenderWindowInteractorRef)getInteractor;
- (void)setupPipeline;
@end
/*=========================================================================
Program: Visualization Toolkit
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
#import "MyGLKViewController.h"
@interface MyGLKViewController () {
vesKiwiViewerApp::Ptr mKiwiApp;
MyGestureHandler* mGestureHandler;
}
@property (strong, nonatomic) EAGLContext *context;
- (void)tearDownGL;
@end
@implementation MyGLKViewController
//----------------------------------------------------------------------------
- (vtkIOSRenderWindow *)getVTKRenderWindow
{
return _myVTKRenderWindow;
}
//----------------------------------------------------------------------------
- (void)setVTKRenderWindow:(vtkIOSRenderWindow *)theVTKRenderWindow
{
_myVTKRenderWindow = theVTKRenderWindow;
}
//----------------------------------------------------------------------------
- (vtkIOSRenderWindowInteractor *)getInteractor
{
if (_myVTKRenderWindow)
{
return (vtkIOSRenderWindowInteractor *)_myVTKRenderWindow->GetInteractor();
}
else
{
return NULL;
}
}
- (void)setupPipeline
{
vtkRenderingOpenGL2ObjectFactory *of = vtkRenderingOpenGL2ObjectFactory::New();
vtkObjectFactory::RegisterFactory(of);
vtkIOSRenderWindow *renWin = vtkIOSRenderWindow::New();
//renWin->DebugOn();
[self setVTKRenderWindow:renWin];
vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
iren->SetRenderWindow(renWin);
vtkNew<vtkRenderer> renderer;
renWin->AddRenderer(renderer.Get());
vtkInteractorStyleMultiTouchCamera *ismt = vtkInteractorStyleMultiTouchCamera::New();
iren->SetInteractorStyle(ismt);
ismt->Delete();
vtkNew<vtkSphereSource> sphere;
sphere->SetThetaResolution(8);
sphere->SetPhiResolution(8);
vtkNew<vtkPolyDataMapper> sphereMapper;
sphereMapper->SetInputConnection(sphere->GetOutputPort());
vtkNew<vtkActor> sphereActor;
sphereActor->SetMapper(sphereMapper.Get());
vtkNew<vtkConeSource> cone;
cone->SetResolution(6);
vtkNew<vtkGlyph3D> glyph;
glyph->SetInputConnection(sphere->GetOutputPort());
glyph->SetSourceConnection(cone->GetOutputPort());
glyph->SetVectorModeToUseNormal();
glyph->SetScaleModeToScaleByVector();
glyph->SetScaleFactor(0.25);
vtkNew<vtkPolyDataMapper> spikeMapper;
spikeMapper->SetInputConnection(glyph->GetOutputPort());
vtkNew<vtkActor> spikeActor;
spikeActor->SetMapper(spikeMapper.Get());
renderer->AddActor(sphereActor.Get());
renderer->AddActor(spikeActor.Get());
renderer->SetBackground(0.4,0.5,0.6);
}
- (void)viewDidLoad
{
[super viewDidLoad];
self.context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2];
if (!self.context) {
NSLog(@"Failed to create ES context");
}
GLKView *view = (GLKView *)self.view;
view.context = self.context;
view.drawableDepthFormat = GLKViewDrawableDepthFormat24;
view.drawableMultisample = GLKViewDrawableMultisample4X;
// setup the vis pipeline
[self setupPipeline];
[self getVTKRenderWindow]->SetSize(backingWidth, backingHeight);
[self getVTKRenderWindow]->Render();
}
-(void) initializeKiwiApp
{
[EAGLContext setCurrentContext:self.context];
std::string dataset = [[[NSBundle mainBundle] pathForResource:@"teapot" ofType:@"vtp"] UTF8String];
self->mKiwiApp = vesKiwiViewerApp::Ptr(new vesKiwiViewerApp);
self->mKiwiApp->initGL();
[self resizeView];
self->mKiwiApp->loadDataset(dataset);
self->mKiwiApp->resetView();
}
- (void)dealloc
{
[self tearDownGL];
if ([EAGLContext currentContext] == self.context) {
[EAGLContext setCurrentContext:nil];
}
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
if ([self isViewLoaded] && ([[self view] window] == nil)) {
self.view = nil;
[self tearDownGL];
if ([EAGLContext currentContext] == self.context) {
[EAGLContext setCurrentContext:nil];
}
self.context = nil;
}
// Dispose of any resources that can be recreated.
}
- (void)tearDownGL
{
[EAGLContext setCurrentContext:self.context];
// free GL resources
// ...
}
-(void) resizeView
{
double scale = self.view.contentScaleFactor;
[self getVTKRenderWindow]->SetSize(self.view.bounds.size.width*scale, self.view.bounds.size.height*scale);
}
- (void)viewWillLayoutSubviews
{
[self resizeView];
}
- (void)glkView:(GLKView *)view drawInRect:(CGRect)rect
{
[self getVTKRenderWindow]->Render();
}
@end
/*=========================================================================
Program: Visualization Toolkit
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
#import <vtkIOSGLView.h>
//CLASS INTERFACES:
@interface PaintingView : vtkIOSGLView
@end
/*=========================================================================
Program: Visualization Toolkit
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
#import <QuartzCore/QuartzCore.h>
#import <OpenGLES/EAGLDrawable.h>
#import <GLKit/GLKit.h>
#import "PaintingView.h"
#include "vtkNew.h"
#include "vtkActor.h"
#include "vtkCamera.h"
#include "vtkConeSource.h"
#include "vtkDebugLeaks.h"
#include "vtkGlyph3D.h"
#include "vtkPolyData.h"
#include "vtkPolyDataMapper.h"
#include "vtkIOSRenderWindow.h"
#include "vtkIOSRenderWindowInteractor.h"
#include "vtkRenderer.h"
#include "vtkSphereSource.h"
#include "vtkCommand.h"
#include "vtkInteractorStyleMultiTouchCamera.h"
@interface PaintingView()
{
}
@end
@implementation PaintingView
- (void)setupPipeline
{
[super setupPipeline];
vtkIOSRenderWindowInteractor *interactor = [self getInteractor];
if (!interactor)
{
return;
}
vtkIOSRenderWindow *renWin = [self getVTKRenderWindow];
if (!renWin)
{
return;
}
vtkNew<vtkRenderer> renderer;
renWin->AddRenderer(renderer.Get());
vtkInteractorStyleMultiTouchCamera *ismt = vtkInteractorStyleMultiTouchCamera::New();
interactor->SetInteractorStyle(ismt);
ismt->Delete();
vtkNew<vtkSphereSource> sphere;
sphere->SetThetaResolution(8);
sphere->SetPhiResolution(8);
vtkNew<vtkPolyDataMapper> sphereMapper;
sphereMapper->SetInputConnection(sphere->GetOutputPort());
vtkNew<vtkActor> sphereActor;
sphereActor->SetMapper(sphereMapper.Get());
vtkNew<vtkConeSource> cone;
cone->SetResolution(6);
vtkNew<vtkGlyph3D> glyph;
glyph->SetInputConnection(sphere->GetOutputPort());
glyph->SetSourceConnection(cone->GetOutputPort());
glyph->SetVectorModeToUseNormal();
glyph->SetScaleModeToScaleByVector();
glyph->SetScaleFactor(0.25);
vtkNew<vtkPolyDataMapper> spikeMapper;
spikeMapper->SetInputConnection(glyph->GetOutputPort());
vtkNew<vtkActor> spikeActor;
spikeActor->SetMapper(spikeMapper.Get());
renderer->AddActor(sphereActor.Get());
renderer->AddActor(spikeActor.Get());
renderer->SetBackground(0.4,0.5,0.6);
}
@end
/*=========================================================================
Program: Visualization Toolkit
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
#import <UIKit/UIKit.h>
@interface PaintingViewController : UIViewController
@end
/*=========================================================================
Program: Visualization Toolkit
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
#import "PaintingViewController.h"
#import "PaintingView.h"
//CLASS IMPLEMENTATIONS:
@interface PaintingViewController()
{
CFTimeInterval lastTime;
}
@end
@implementation PaintingViewController
- (void)viewDidLoad
{
[super viewDidLoad];
}
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
[self becomeFirstResponder];
}
- (BOOL)canBecomeFirstResponder