ctkVTKThumbnailViewTest1.cpp 2.2 KB

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