ctkVTKRenderViewTest1.cpp 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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 <QDebug>
  17. #include <QTimer>
  18. // VTK includes
  19. #include <vtkActor.h>
  20. #include <vtkNew.h>
  21. #include <vtkPolyDataMapper.h>
  22. #include <vtkRenderer.h>
  23. #include <vtkSphereSource.h>
  24. #if CTK_USE_QVTKOPENGLWIDGET
  25. #include <QVTKOpenGLWidget.h>
  26. #endif
  27. // CTK includes
  28. #include "ctkVTKRenderView.h"
  29. #include "ctkCommandLineParser.h"
  30. // STD includes
  31. #include <iostream>
  32. //-----------------------------------------------------------------------------
  33. int ctkVTKRenderViewTest1(int argc, char * argv [] )
  34. {
  35. #if CTK_USE_QVTKOPENGLWIDGET
  36. QSurfaceFormat format = QVTKOpenGLWidget::defaultFormat();
  37. format.setSamples(0);
  38. QSurfaceFormat::setDefaultFormat(format);
  39. #endif
  40. QApplication app(argc, argv);
  41. // Command line parser
  42. ctkCommandLineParser parser;
  43. parser.addArgument("", "-I", QVariant::Bool);
  44. QHash<QString, QVariant> parsedArgs = parser.parseArguments(app.arguments());
  45. bool interactive = parsedArgs["-I"].toBool();
  46. // Instanciate widget
  47. ctkVTKRenderView renderView;
  48. renderView.setBackgroundColor(QColor(Qt::red));
  49. renderView.setBackgroundColor2(QColor(Qt::yellow));
  50. renderView.setGradientBackground(true);
  51. renderView.setCornerAnnotationText("CTK Rocks !");
  52. renderView.show();
  53. // Instanciate VTK objects
  54. vtkNew<vtkSphereSource> sphere;
  55. vtkNew<vtkPolyDataMapper> sphereMapper;
  56. vtkNew<vtkActor> sphereActor;
  57. // Configure actor
  58. sphere->SetRadius(0.25);
  59. sphereMapper->SetInputConnection(sphere->GetOutputPort());
  60. sphereActor->SetMapper(sphereMapper.GetPointer());
  61. // Add actor
  62. renderView.renderer()->AddActor(sphereActor.GetPointer());
  63. renderView.lookFromAxis(ctkAxesWidget::Right);
  64. renderView.lookFromAxis(ctkAxesWidget::Left, 10);
  65. renderView.lookFromAxis(ctkAxesWidget::Anterior, 1.);
  66. renderView.lookFromAxis(ctkAxesWidget::Posterior, 1.);
  67. renderView.lookFromAxis(ctkAxesWidget::Superior, 0.333333);
  68. renderView.lookFromAxis(ctkAxesWidget::Inferior, 0.333333);
  69. renderView.lookFromAxis(ctkAxesWidget::None, 100.);
  70. if (!interactive)
  71. {
  72. QTimer::singleShot(200, &app, SLOT(quit()));
  73. }
  74. return app.exec();
  75. }