ctkVTKRenderViewTest2.cpp 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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 <vtkSmartPointer.h>
  21. #include <vtkRenderer.h>
  22. #include <vtkPolyDataMapper.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 ctkVTKRenderViewTest2(int argc, char * argv [] )
  34. {
  35. QApplication app(argc, argv);
  36. // Command line parser
  37. ctkCommandLineParser parser;
  38. parser.addArgument("", "-I", QVariant::Bool);
  39. parser.addArgument("", "-D", QVariant::String);
  40. bool ok = false;
  41. QHash<QString, QVariant> parsedArgs = parser.parseArguments(app.arguments(), &ok);
  42. if (!ok)
  43. {
  44. std::cerr << qPrintable(parser.errorString()) << std::endl;
  45. return EXIT_FAILURE;
  46. }
  47. bool interactive = parsedArgs["-I"].toBool();
  48. QString data_directory = parsedArgs["-D"].toString();
  49. Q_UNUSED(data_directory);
  50. // Instanciate widget
  51. ctkVTKRenderView renderView;
  52. renderView.resize(300, 300);
  53. renderView.setBackgroundColor(QColor(Qt::red));
  54. renderView.setCornerAnnotationText("CTK Rocks !");
  55. renderView.show();
  56. // Instanciate VTK objects
  57. VTK_CREATE(vtkSphereSource, sphere);
  58. VTK_CREATE(vtkPolyDataMapper, sphereMapper);
  59. VTK_CREATE(vtkActor, sphereActor);
  60. // Configure actor
  61. sphere->SetRadius(0.25);
  62. sphereMapper->SetInputConnection(sphere->GetOutputPort());
  63. sphereActor->SetMapper(sphereMapper);
  64. // Add actor
  65. renderView.renderer()->AddActor(sphereActor);
  66. renderView.lookFromAxis(ctkAxesWidget::Right);
  67. renderView.lookFromAxis(ctkAxesWidget::Left, 10);
  68. renderView.lookFromAxis(ctkAxesWidget::Anterior, 1.);
  69. renderView.lookFromAxis(ctkAxesWidget::Posterior, 1.);
  70. renderView.lookFromAxis(ctkAxesWidget::Superior, 0.333333);
  71. renderView.lookFromAxis(ctkAxesWidget::Inferior, 0.333333);
  72. renderView.lookFromAxis(ctkAxesWidget::None, 100.);
  73. if (!interactive)
  74. {
  75. QTimer::singleShot(1000, &app, SLOT(quit()));
  76. }
  77. return app.exec();
  78. }