ctkVTKRenderViewTest2.cpp 2.8 KB

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