File: igstkQTWidgetTest2.cxx

package info (click to toggle)
igstk 4.4.0-2
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 38,980 kB
  • sloc: cpp: 86,267; xml: 96; makefile: 75; python: 38
file content (178 lines) | stat: -rw-r--r-- 5,811 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
/*=========================================================================

  Program:   Image Guided Surgery Software Toolkit
  Module:    $RCSfile: igstkQTWidgetTest2.cxx,v $
  Language:  C++
  Date:      $Date: 2008-02-13 16:27:27 $
  Version:   $Revision: 1.2 $

  Copyright (c) ISC  Insight Software Consortium.  All rights reserved.
  See IGSTKCopyright.txt or http://www.igstk.org/copyright.htm for details.

     This software is distributed WITHOUT ANY WARRANTY; without even
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
     PURPOSE.  See the above copyright notices for more information.

=========================================================================*/

#if defined(_MSC_VER)
//  Warning about: identifier was truncated to '255' characters in the 
//  debug information (MVC6.0 Debug)
#pragma warning( disable : 4786 )
#endif

// QT header files
#include <QApplication>
#include <QMainWindow>
#include <QGridLayout>
#include <QtTest/QTest>

#include <iostream>
#include "igstkView2D.h"
#include "igstkEvents.h"
#include "igstkEllipsoidObject.h"
#include "igstkCylinderObject.h"
#include "igstkEllipsoidObjectRepresentation.h"
#include "igstkCylinderObjectRepresentation.h"
#include "igstkVTKLoggerOutput.h"
#include "igstkQTWidget.h"

#include "igstkLogger.h"
#include "itkStdStreamLogOutput.h"

int igstkQTWidgetTest2( int argc, char * argv[]) 
{
  igstk::RealTimeClock::Initialize();

  typedef igstk::Object::LoggerType   LoggerType;
  typedef itk::StdStreamLogOutput     LogOutputType;
  
  // logger object created for logging mouse activities
  LoggerType::Pointer   logger = LoggerType::New();
  LogOutputType::Pointer logOutput = LogOutputType::New();
  logOutput->SetStream( std::cout );
  logger->AddLogOutput( logOutput );
  logger->SetPriorityLevel( itk::Logger::DEBUG );

  // Create an igstk::VTKLoggerOutput and then test it.
  igstk::VTKLoggerOutput::Pointer vtkLoggerOutput = 
                                                igstk::VTKLoggerOutput::New();
  vtkLoggerOutput->OverrideVTKWindow();
  vtkLoggerOutput->SetLogger(logger);  // redirect messages from 
                                       // VTK OutputWindow -> logger

  try
    {
    // Create an QT minimal GUI
    QApplication app(argc, argv);
    QMainWindow  * qtMainWindow = new QMainWindow();
    qtMainWindow->setFixedSize(601,301);

    typedef igstk::QTWidget      QTWidgetType;
    typedef igstk::View2D        View2DType;

    //Instantiate widget and view component
    QTWidgetType * qtWidget2D = new QTWidgetType();
    View2DType::Pointer view2D = View2DType::New();
    view2D->SetLogger( logger );
    view2D->RequestResetCamera();

    qtWidget2D->SetLogger( logger );
    qtWidget2D->RequestSetView( view2D );

    //Instantiate a second widget and a view component
    QTWidgetType * qtWidget2D2 = new QTWidgetType();
    View2DType::Pointer view2D2 = View2DType::New();
    view2D2->SetLogger( logger );
    view2D2->RequestResetCamera();

    qtWidget2D2->SetLogger( logger );
    qtWidget2D2->RequestSetView( view2D2 );
    qtWidget2D2->setGeometry(QRect(260,10,255,301));

    QGridLayout *widgetLayout = new QGridLayout();
    QWidget     *widgetGroup  = new QWidget();

    widgetLayout->addWidget(qtWidget2D, 0, 0);
    widgetLayout->addWidget(qtWidget2D2, 0, 1);
    widgetGroup->setLayout(widgetLayout);
    qtMainWindow->setCentralWidget( widgetGroup );

    // Create the ellipsoid 
    igstk::EllipsoidObject::Pointer ellipsoid = igstk::EllipsoidObject::New();
    ellipsoid->SetRadius(1.0,2.0,3.0);
   
    // Create the ellipsoid representation
    igstk::EllipsoidObjectRepresentation::Pointer ellipsoidRepresentation =
                             igstk::EllipsoidObjectRepresentation::New();

    ellipsoidRepresentation->RequestSetEllipsoidObject( ellipsoid );
    ellipsoidRepresentation->SetColor(0.0,1.0,0.0);
    ellipsoidRepresentation->SetOpacity(1.0);

    const double validityTimeInMilliseconds = 1e300; // 100 seconds
    igstk::Transform transform;
    igstk::Transform::VectorType translation;
    translation[0] = 0;
    translation[1] = 0;
    translation[2] = 0;
    igstk::Transform::VersorType rotation;
    rotation.Set( 0.0, 0.0, 0.0, 1.0 );
    igstk::Transform::ErrorType errorValue = 10; // 10 millimeters

    transform.SetTranslationAndRotation( 
        translation, rotation, errorValue, validityTimeInMilliseconds );
  
#ifdef USE_SPATIAL_OBJECT_DEPRECATED
    ellipsoid->RequestSetTransform( transform );
#endif

    // Add the ellipsoid to the view
    view2D->RequestAddObject( ellipsoidRepresentation );

    // Create the ellipsoid representation
    igstk::EllipsoidObjectRepresentation::Pointer ellipsoidRepresentation2 =
                             igstk::EllipsoidObjectRepresentation::New();

    ellipsoidRepresentation2->RequestSetEllipsoidObject( ellipsoid );
    ellipsoidRepresentation2->SetColor(0.0,0.0,1.0);
    ellipsoidRepresentation->SetOpacity(1.0);
    // Add the ellipsoid to the view
    view2D2->RequestAddObject( ellipsoidRepresentation2 );

    // Set the refresh rate and start 
    // the pulse generators of the views.
    view2D->SetRefreshRate( 30 );
    view2D->RequestStart();

    view2D2->SetRefreshRate( 30 );
    view2D2->RequestStart();

    view2D->RequestResetCamera();
    view2D2->RequestResetCamera();

    qtMainWindow->show();

    for( unsigned int i=0; i <= 50; i++ )
      {
      QTest::qWait(10);
      igstk::PulseGenerator::CheckTimeouts();
      }
    
    delete qtWidget2D;
    delete qtWidget2D2;
    delete qtMainWindow;
    }
  catch(...)
    {
    std::cerr << "Exception catched !!" << std::endl;
    return EXIT_FAILURE;
    }

  if( vtkLoggerOutput->GetNumberOfErrorMessages()  > 0 )
    {
    return EXIT_FAILURE;
    }
 
  return EXIT_SUCCESS;
}