ctkVTKRenderViewTest1.cpp 2.7 KB

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