ctkVTKRenderViewTest1.cpp 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /*=========================================================================
  2. Library: CTK
  3. Copyright (c) 2010 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.commontk.org/LICENSE
  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 ctkVTKRenderViewTest1(int argc, char * argv [] )
  34. {
  35. QApplication app(argc, argv);
  36. // Test arguments
  37. bool interactive = false;
  38. QString data_directory;
  39. // Command line parser
  40. ctkCommandLineParser parser;
  41. parser.addBooleanArgument(0, "-I", &interactive);
  42. parser.addStringArgument(0, "-D", &data_directory);
  43. if (!parser.parseArguments(app.arguments()))
  44. {
  45. std::cerr << qPrintable(parser.errorString()) << std::endl;
  46. return EXIT_FAILURE;
  47. }
  48. // Instanciate widget
  49. ctkVTKRenderView renderView;
  50. renderView.resize(300, 300);
  51. renderView.setBackgroundColor(QColor(Qt::red));
  52. renderView.setCornerAnnotationText("CTK Rocks !");
  53. renderView.show();
  54. // Instanciate VTK objects
  55. VTK_CREATE(vtkSphereSource, sphere);
  56. VTK_CREATE(vtkPolyDataMapper, sphereMapper);
  57. VTK_CREATE(vtkActor, sphereActor);
  58. // Configure actor
  59. sphere->SetRadius(0.25);
  60. sphereMapper->SetInputConnection(sphere->GetOutputPort());
  61. sphereActor->SetMapper(sphereMapper);
  62. // Add actor
  63. renderView.renderer()->AddActor(sphereActor);
  64. if (!interactive)
  65. {
  66. QTimer::singleShot(1000, &app, SLOT(quit()));
  67. }
  68. return app.exec();
  69. }