ctkVTKRenderViewTest2.cpp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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. #include <QGroupBox>
  18. #include <QDebug>
  19. // VTK includes
  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 ctkVTKRenderViewTest2(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. parser.addArgument("", "-D", QVariant::String);
  45. bool ok = false;
  46. QHash<QString, QVariant> parsedArgs = parser.parseArguments(app.arguments(), &ok);
  47. if (!ok)
  48. {
  49. std::cerr << qPrintable(parser.errorString()) << std::endl;
  50. return EXIT_FAILURE;
  51. }
  52. bool interactive = parsedArgs["-I"].toBool();
  53. QString data_directory = parsedArgs["-D"].toString();
  54. Q_UNUSED(data_directory);
  55. // Instanciate widget
  56. ctkVTKRenderView renderView;
  57. renderView.resize(300, 300);
  58. renderView.setBackgroundColor(QColor(Qt::red));
  59. renderView.setCornerAnnotationText("CTK Rocks !");
  60. renderView.show();
  61. // Instanciate VTK objects
  62. vtkNew<vtkSphereSource> sphere;
  63. vtkNew<vtkPolyDataMapper> sphereMapper;
  64. vtkNew<vtkActor> sphereActor;
  65. // Configure actor
  66. sphere->SetRadius(0.25);
  67. sphereMapper->SetInputConnection(sphere->GetOutputPort());
  68. sphereActor->SetMapper(sphereMapper.GetPointer());
  69. // Add actor
  70. renderView.renderer()->AddActor(sphereActor.GetPointer());
  71. renderView.lookFromAxis(ctkAxesWidget::Right);
  72. renderView.lookFromAxis(ctkAxesWidget::Left, 10);
  73. renderView.lookFromAxis(ctkAxesWidget::Anterior, 1.);
  74. renderView.lookFromAxis(ctkAxesWidget::Posterior, 1.);
  75. renderView.lookFromAxis(ctkAxesWidget::Superior, 0.333333);
  76. renderView.lookFromAxis(ctkAxesWidget::Inferior, 0.333333);
  77. renderView.lookFromAxis(ctkAxesWidget::None, 100.);
  78. if (!interactive)
  79. {
  80. QTimer::singleShot(1000, &app, SLOT(quit()));
  81. }
  82. return app.exec();
  83. }