1 /*========================================================================= 2 3 Library: CTK 4 5 Copyright (c) Kitware Inc. 6 7 Licensed under the Apache License, Version 2.0 (the "License"); 8 you may not use this file except in compliance with the License. 9 You may obtain a copy of the License at 10 11 http://www.apache.org/licenses/LICENSE-2.0.txt 12 13 Unless required by applicable law or agreed to in writing, software 14 distributed under the License is distributed on an "AS IS" BASIS, 15 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 See the License for the specific language governing permissions and 17 limitations under the License. 18 19 =========================================================================*/ 20 21 // QT includes 22 #include <QApplication> 23 #include <QTimer> 24 25 // qMRML includes 26 #include "ctkVTKThumbnailView.h" 27 28 // VTK includes 29 #include <vtkSmartPointer.h> 30 #if CTK_USE_QVTKOPENGLWIDGET 31 #include <QVTKOpenGLWidget.h> 32 #endif 33 34 #include <vtkActor.h> 35 #include <vtkCubeSource.h> 36 #include <vtkPolyDataMapper.h> 37 #include <vtkRenderer.h> 38 #include <vtkRenderWindow.h> 39 #include <vtkRenderWindowInteractor.h> 40 #include <vtkVersion.h> 41 42 // STD includes 43 #include <cstdlib> 44 #include <iostream> 45 ctkVTKThumbnailViewTest1(int argc,char * argv[])46int ctkVTKThumbnailViewTest1(int argc, char * argv [] ) 47 { 48 #if CTK_USE_QVTKOPENGLWIDGET 49 QSurfaceFormat format = QVTKOpenGLWidget::defaultFormat(); 50 format.setSamples(0); 51 QSurfaceFormat::setDefaultFormat(format); 52 #endif 53 54 QApplication app(argc, argv); 55 56 ctkVTKThumbnailView thumbnailView; 57 thumbnailView.setWindowTitle("Thumbnail view"); 58 59 ctkVTKRenderView renderView; 60 renderView.setWindowTitle("Render view"); 61 62 vtkPolyDataMapper *mapper = vtkPolyDataMapper::New(); 63 vtkCubeSource *cube= vtkCubeSource::New(); 64 #if (VTK_MAJOR_VERSION <= 5) 65 mapper->SetInput(cube->GetOutput()); 66 #else 67 mapper->SetInputConnection(cube->GetOutputPort()); 68 #endif 69 cube->Delete(); 70 vtkActor *actor = vtkActor::New(); 71 actor->SetMapper(mapper); 72 mapper->Delete(); 73 74 renderView.renderer()->AddActor(actor); 75 actor->Delete(); 76 77 thumbnailView.setRendererToListen(renderView.renderer()); 78 79 thumbnailView.show(); 80 renderView.show(); 81 82 if (argc < 2 || QString(argv[1]) != "-I" ) 83 { 84 QTimer::singleShot(200, &app, SLOT(quit())); 85 } 86 87 return app.exec(); 88 } 89