ctkVTKRenderViewTest1.cpp 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. QSurfaceFormat::setDefaultFormat(format);
  38. #endif
  39. QApplication app(argc, argv);
  40. // Command line parser
  41. ctkCommandLineParser parser;
  42. parser.addArgument("", "-I", QVariant::Bool);
  43. QHash<QString, QVariant> parsedArgs = parser.parseArguments(app.arguments());
  44. bool interactive = parsedArgs["-I"].toBool();
  45. // Instanciate widget
  46. ctkVTKRenderView renderView;
  47. renderView.setBackgroundColor(QColor(Qt::red));
  48. renderView.setBackgroundColor2(QColor(Qt::yellow));
  49. renderView.setGradientBackground(true);
  50. renderView.setCornerAnnotationText("CTK Rocks !");
  51. renderView.show();
  52. // Instanciate VTK objects
  53. vtkNew<vtkSphereSource> sphere;
  54. vtkNew<vtkPolyDataMapper> sphereMapper;
  55. vtkNew<vtkActor> sphereActor;
  56. // Configure actor
  57. sphere->SetRadius(0.25);
  58. sphereMapper->SetInputConnection(sphere->GetOutputPort());
  59. sphereActor->SetMapper(sphereMapper.GetPointer());
  60. // Add actor
  61. renderView.renderer()->AddActor(sphereActor.GetPointer());
  62. renderView.lookFromAxis(ctkAxesWidget::Right);
  63. renderView.lookFromAxis(ctkAxesWidget::Left, 10);
  64. renderView.lookFromAxis(ctkAxesWidget::Anterior, 1.);
  65. renderView.lookFromAxis(ctkAxesWidget::Posterior, 1.);
  66. renderView.lookFromAxis(ctkAxesWidget::Superior, 0.333333);
  67. renderView.lookFromAxis(ctkAxesWidget::Inferior, 0.333333);
  68. renderView.lookFromAxis(ctkAxesWidget::None, 100.);
  69. if (!interactive)
  70. {
  71. QTimer::singleShot(200, &app, SLOT(quit()));
  72. }
  73. return app.exec();
  74. }