GOFIGURE2
0.9.0
Main Page
Related Pages
Modules
Namespaces
Classes
Files
Examples
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Properties
Friends
Macros
Groups
Pages
Code
GUI
lib
SynchronizedViews
QGoSynchronizedView2D.cxx
Go to the documentation of this file.
1
/*=========================================================================
2
Authors: The GoFigure Dev. Team.
3
at Megason Lab, Systems biology, Harvard Medical school, 2009-11
4
5
Copyright (c) 2009-11, President and Fellows of Harvard College.
6
All rights reserved.
7
8
Redistribution and use in source and binary forms, with or without
9
modification, are permitted provided that the following conditions are met:
10
11
Redistributions of source code must retain the above copyright notice,
12
this list of conditions and the following disclaimer.
13
Redistributions in binary form must reproduce the above copyright notice,
14
this list of conditions and the following disclaimer in the documentation
15
and/or other materials provided with the distribution.
16
Neither the name of the President and Fellows of Harvard College
17
nor the names of its contributors may be used to endorse or promote
18
products derived from this software without specific prior written
19
permission.
20
21
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
23
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24
PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
25
BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
26
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
27
OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
28
OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
29
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
30
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
31
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32
33
=========================================================================*/
34
#include "
QGoSynchronizedView2D.h
"
35
36
#include "
QGoSynchronizedView2DCallbacks.h
"
37
#include "vtkImageData.h"
38
#include "
vtkViewImage2D.h
"
39
#include "vtkEventQtSlotConnect.h"
40
41
#include "
SnapshotHelper.h
"
42
#include "
QGoImageView2D.h
"
43
#include "
QGoSynchronizedViewManager.h
"
44
45
#include "
itkImageToVTKImageFilter.h
"
46
#include "itkSmartPointer.h"
47
#include "itkImage.h"
48
//--------------------------------------------------------------------------
49
/*
50
* Default Constructor.
51
* \param iSynchronizedViewName
52
* \param iParent
53
*/
54
QGoSynchronizedView2D::QGoSynchronizedView2D
(
QString
iViewName,
QWidget
*iParent) :
55
QGoSynchronizedView
(iViewName, iParent),
56
m_View (NULL)
57
{
58
}
59
60
//--------------------------------------------------------------------------
61
QGoSynchronizedView2D::
62
~QGoSynchronizedView2D
()
63
{
64
// remove the comparer from the manager
65
if
(
m_ViewManager
!= NULL )
66
{
67
m_ViewManager
->
removeSynchronizedView2D
(
this
);
68
m_ViewManager
= NULL;
69
}
70
71
// delete the view if any
72
if
(
HasViewer
() )
73
{
74
deleteViewer
();
75
}
76
}
77
78
//--------------------------------------------------------------------------
79
/* Print self informations */
80
void
81
QGoSynchronizedView2D::PrintOs
(ostream & os)
82
{
83
// if we have an imageview, the we print its image information
84
if
(
m_Image
)
85
{
86
os <<
"SynchronizedView 2D "
<<
this
<<
" contains :"
<< std::endl;
87
m_Image
->Print(os);
88
}
89
else
90
{
91
os <<
"SynchronizedView 2D "
<<
this
<<
" contains no Image :"
<< std::endl;
92
}
93
}
94
95
//--------------------------------------------------------------------------
96
/* Update the viewer contained in the widget */
97
void
98
QGoSynchronizedView2D::Update
()
99
{
100
if
(
m_View
)
101
{
102
this->
m_View
->
Update
();
103
// in addition to standard parameters, we don't want to interpolate data
104
this->
m_View
->
SetInterpolate
(0);
105
}
106
}
107
108
//--------------------------------------------------------------------------
109
/* render the viewer contained in the widget if any */
110
void
111
QGoSynchronizedView2D::Render
()
112
{
113
if
(
m_View
)
114
{
115
m_View
->
GetImageViewer
(0)->
Render
();
116
}
117
}
118
119
//--------------------------------------------------------------------------
120
/* get the camera of the viewer */
121
vtkCamera *
122
QGoSynchronizedView2D::GetCamera
()
123
{
124
if
(
m_View
)
125
{
126
return
m_View
->
GetImageViewer
(0)
127
->GetRenderer()
128
->GetActiveCamera();
129
}
130
else
131
{
132
return
NULL;
133
}
134
}
135
136
//--------------------------------------------------------------------------
137
/* true if the widget has a viewer */
138
bool
139
QGoSynchronizedView2D::HasViewer
()
140
{
141
return
(
m_View
!= NULL );
142
}
143
144
//--------------------------------------------------------------------------
145
/* returns the type of comparer (2 for 2D, 3 for 3D) */
146
int
147
QGoSynchronizedView2D::GetSynchronizedViewType
()
148
{
149
return
2;
150
}
151
152
//--------------------------------------------------------------------------
153
/* set the image to be displaid */
154
void
155
QGoSynchronizedView2D::SetImage
(vtkImageData *iImage)
156
{
157
if
( iImage )
158
{
159
// if there is no viewer, we create one
160
if
( !
m_View
)
161
{
162
createViewer
();
163
}
164
// set the image to the view
165
dynamic_cast<
QGoImageView2D
*
>
(
m_View
)->
SetImage
(iImage);
166
// update image
167
m_Image
= iImage;
168
169
this->
Update
();
170
}
171
}
172
173
// ########################################################################
174
// Private
175
176
//--------------------------------------------------------------------------
177
/* delete the viewer contained in the widget */
178
void
179
QGoSynchronizedView2D::deleteViewer
()
180
{
181
// if there is no viewer
182
if
(
m_View
)
183
{
184
// delete object
185
delete
(
m_View
);
186
// set pointer to NULL
187
m_View
= NULL;
188
}
189
}
190
191
//--------------------------------------------------------------------------
192
// create the viewer contained in the widget
193
void
194
QGoSynchronizedView2D::createViewer
()
195
{
196
// if there is already a viewer
197
if
( !
m_View
)
198
{
199
// else we create one
200
QGoImageView2D
*v =
new
QGoImageView2D
(
this
);
201
v->
setContentsMargins
(1, 1, 1, 1);
202
203
// setup position of the widget
204
this->gridLayout->addWidget(v);
205
206
m_View
= v;
207
}
208
}
209
210
//--------------------------------------------------------------------------
211
QGoImageView2D
*
212
QGoSynchronizedView2D::GetImageView
()
213
{
214
if
(
HasViewer
() )
215
{
216
return
dynamic_cast<
QGoImageView2D
*
>
(
m_View
);
217
}
218
else
219
{
220
return
NULL;
221
}
222
}
223
224
//--------------------------------------------------------------------------
225
QString
226
QGoSynchronizedView2D::SnapshotViewXY
(
const
GoFigure::FileType
& iType,
227
const
QString
& iBaseName)
228
{
229
QGoImageView2D
*viewer =
GetImageView
();
230
231
if
( viewer )
232
{
233
return
viewer->
SnapshotViewXY
(iType, iBaseName);
234
}
235
else
236
{
237
return
QString
();
238
}
239
}
Generated on Mon May 27 2013 08:47:30 for GOFIGURE2 by
1.8.1.2