ctkVTKRenderViewTest1.cpp 2.6 KB

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