1 /*=========================================================================
2 
3   Library:   CTK
4 
5   Copyright (c) Kitware Inc.
6 
7   Licensed under the Apache License, Version 2.0 (the "License");
8   you may not use this file except in compliance with the License.
9   You may obtain a copy of the License at
10 
11       http://www.apache.org/licenses/LICENSE-2.0.txt
12 
13   Unless required by applicable law or agreed to in writing, software
14   distributed under the License is distributed on an "AS IS" BASIS,
15   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16   See the License for the specific language governing permissions and
17   limitations under the License.
18 
19 =========================================================================*/
20 
21 // Qt includes
22 #include <QApplication>
23 #include <QTimer>
24 #include <QGroupBox>
25 #include <QDebug>
26 
27 // VTK includes
28 #include <vtkNew.h>
29 #include <vtkPolyDataMapper.h>
30 #include <vtkRenderer.h>
31 #include <vtkSphereSource.h>
32 #if CTK_USE_QVTKOPENGLWIDGET
33 #include <QVTKOpenGLWidget.h>
34 #endif
35 
36 // CTK includes
37 #include "ctkVTKRenderView.h"
38 #include "ctkCommandLineParser.h"
39 
40 // STD includes
41 #include <iostream>
42 
43 //-----------------------------------------------------------------------------
ctkVTKRenderViewTest2(int argc,char * argv[])44 int ctkVTKRenderViewTest2(int argc, char * argv [] )
45 {
46 #if CTK_USE_QVTKOPENGLWIDGET
47     QSurfaceFormat format = QVTKOpenGLWidget::defaultFormat();
48     format.setSamples(0);
49     QSurfaceFormat::setDefaultFormat(format);
50 #endif
51 
52   QApplication app(argc, argv);
53 
54   // Command line parser
55   ctkCommandLineParser parser;
56   parser.addArgument("", "-I", QVariant::Bool);
57   parser.addArgument("", "-D", QVariant::String);
58   bool ok = false;
59   QHash<QString, QVariant> parsedArgs = parser.parseArguments(app.arguments(), &ok);
60   if (!ok)
61     {
62     std::cerr << qPrintable(parser.errorString()) << std::endl;
63     return EXIT_FAILURE;
64     }
65 
66   bool interactive = parsedArgs["-I"].toBool();
67   QString data_directory = parsedArgs["-D"].toString();
68   Q_UNUSED(data_directory);
69 
70   // Instanciate widget
71   ctkVTKRenderView renderView;
72   renderView.resize(300, 300);
73   renderView.setBackgroundColor(QColor(Qt::red));
74   renderView.setCornerAnnotationText("CTK Rocks !");
75   renderView.show();
76 
77   // Instanciate VTK objects
78   vtkNew<vtkSphereSource> sphere;
79   vtkNew<vtkPolyDataMapper> sphereMapper;
80   vtkNew<vtkActor> sphereActor;
81 
82   // Configure actor
83   sphere->SetRadius(0.25);
84   sphereMapper->SetInputConnection(sphere->GetOutputPort());
85   sphereActor->SetMapper(sphereMapper.GetPointer());
86 
87   // Add actor
88   renderView.renderer()->AddActor(sphereActor.GetPointer());
89 
90   renderView.lookFromAxis(ctkAxesWidget::Right);
91   renderView.lookFromAxis(ctkAxesWidget::Left, 10);
92   renderView.lookFromAxis(ctkAxesWidget::Anterior, 1.);
93   renderView.lookFromAxis(ctkAxesWidget::Posterior, 1.);
94   renderView.lookFromAxis(ctkAxesWidget::Superior, 0.333333);
95   renderView.lookFromAxis(ctkAxesWidget::Inferior, 0.333333);
96   renderView.lookFromAxis(ctkAxesWidget::None, 100.);
97 
98   if (!interactive)
99     {
100     QTimer::singleShot(1000, &app, SLOT(quit()));
101     }
102   return app.exec();
103 }
104