GOFIGURE2  0.9.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
QGoSynchronizedView3D.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 "QGoSynchronizedView3D.h"
35 
37 #include "vtkImageData.h"
38 #include "vtkViewImage3D.h"
39 #include "vtkViewImage2D.h"
40 #include "vtkEventQtSlotConnect.h"
41 #include "QGoImageView3D.h"
43 #include "SnapshotHelper.h"
44 
45 //--------------------------------------------------------------------------
47  QWidget *iParent) :
48  QGoSynchronizedView(iViewName, iParent),
49  m_View (NULL)
50 {
51 }
52 
53 //--------------------------------------------------------------------------
56 {
57  // remove the SynchronizedView from the orchestra
58  if ( m_ViewManager )
59  {
61  m_ViewManager = NULL;
62  }
63 
64  // delete the view if any
65  if ( m_View )
66  {
67  // we delete the viewer
68  delete ( m_View );
69  m_View = NULL;
70  }
71 }
72 
73 //--------------------------------------------------------------------------
74 /* Update the viewer contained in the widget */
75 void
77 {
78  if ( m_View )
79  {
80  this->m_View->Update();
81  // in addition to standard parameters, we don't want to interpolate data
82  this->m_View->SetInterpolate(0);
83  }
84 }
85 
86 //--------------------------------------------------------------------------
87 void
89 {
90  // if we have an imageview, the we print its image information
91  if ( m_Image != NULL )
92  {
93  os << "SynchronizedView 3D " << this << " contains :" << std::endl;
94  m_Image->Print(os);
95  }
96  else
97  {
98  os << "SynchronizedView 3D " << this << " contains no Image :" << std::endl;
99  }
100 }
101 
102 //--------------------------------------------------------------------------
103 /* returns the type of SynchronizedView (2 for 2D, 3 for 3D) */
104 int
106 {
107  return 3;
108 }
109 
110 //--------------------------------------------------------------------------
111 void
112 QGoSynchronizedView3D::SetImage(vtkImageData *iImage)
113 {
114  if ( iImage )
115  {
116  // if there is no viewer, we create one
117  if ( !m_View )
118  {
119  createViewer();
120  }
121  // set the image to the current view
122  m_View->SetImage(iImage);
123  // update current image
124  m_Image = iImage;
125  this->Update();
126  }
127 }
128 
129 //--------------------------------------------------------------------------
130 void
132 {
133  if ( HasViewer() )
134  {
139  }
140 }
141 
142 //--------------------------------------------------------------------------
143 void
145 {
146  if ( HasViewer() )
147  {
148  if ( ( iId >= 0 ) && ( iId <= 2 ) ) // if we want to render one of the 2D
149  // view
150  {
151  m_View->GetImageViewer(iId)->Render();
152  }
153  else // if we want to render the 3D view
154  {
156  }
157  }
158 }
159 
160 //--------------------------------------------------------------------------
161 /* get the camera of the current viewer */
162 vtkCamera *
164 {
165  int currentView = GetFullScreenView();
166 
167  if ( HasViewer() )
168  {
169  if ( ( currentView >= 1 ) && ( currentView <= 3 ) )
170  {
171  return m_View->GetImageViewer(currentView)
172  ->GetRenderer()
173  ->GetActiveCamera();
174  }
175  else
176  {
177  return m_View->GetImageViewer3D()
178  ->GetRenderer()
179  ->GetActiveCamera();
180  }
181  }
182  return NULL;
183 }
184 
185 //--------------------------------------------------------------------------
186 /* get the camera of the current viewer */
187 vtkCamera *
189 {
190  if ( HasViewer() )
191  {
192  if ( ( iId >= 0 ) && ( iId <= 2 ) )
193  {
194  return m_View->GetImageViewer(iId)
195  ->GetRenderer()
196  ->GetActiveCamera();
197  }
198  else
199  {
200  return m_View->GetImageViewer3D()
201  ->GetRenderer()
202  ->GetActiveCamera();
203  }
204  }
205  return NULL;
206 }
207 
208 //--------------------------------------------------------------------------
209 /* true if the widget has a viewer */
210 bool
212 {
213  return ( m_View != NULL );
214 }
215 
216 //--------------------------------------------------------------------------
217 int
219 {
220  if ( HasViewer() )
221  {
222  return m_View->GetFullScreenView();
223  }
224  else
225  {
226  return -1;
227  }
228 }
229 
230 //--------------------------------------------------------------------------
233 {
234  if ( HasViewer() )
235  {
236  return m_View;
237  }
238  else
239  {
240  return NULL;
241  }
242 }
243 
244 //--------------------------------------------------------------------------
245 QString
247 {
248  QGoImageView3D *viewer = this->GetImageView();
249 
250  if ( HasViewer() )
251  {
252  return viewer->SnapshotViewXY(iType, iBaseName);
253  }
254  else
255  {
256  return QString();
257  }
258 }
259 
260 //--------------------------------------------------------------------------
261 QString
263 {
264  QGoImageView3D *viewer = this->GetImageView();
265 
266  if ( viewer )
267  {
268  return viewer->SnapshotViewXZ(iType, iBaseName);
269  }
270  else
271  {
272  return QString();
273  }
274 }
275 
276 //--------------------------------------------------------------------------
277 QString
279 {
280  QGoImageView3D *viewer = this->GetImageView();
281 
282  if ( viewer )
283  {
284  return viewer->SnapshotViewYZ(iType, iBaseName);
285  }
286  else
287  {
288  return QString();
289  }
290 }
291 
292 //--------------------------------------------------------------------------
293 QString
295 {
296  QGoImageView3D *viewer = this->GetImageView();
297 
298  if ( viewer )
299  {
300  return viewer->SnapshotViewXYZ(iType, iBaseName);
301  }
302  else
303  {
304  return QString();
305  }
306 }
307 
308 //--------------------------------------------------------------------------
309 void
311 {
312  if ( HasViewer() )
313  {
315  }
316 }
317 
318 //--------------------------------------------------------------------------
319 void
321 {
323 }
324 
325 //--------------------------------------------------------------------------
326 void
328 {
330 }
331 
332 //--------------------------------------------------------------------------
333 void
335 {
337 }
338 
339 //--------------------------------------------------------------------------
340 void
342 {
344 }
345 
346 //--------------------------------------------------------------------------
347 void
349 {
351 }
352 
353 // ########################################################################
354 // Private
355 
356 //--------------------------------------------------------------------------
357 /* delete the viewer contained in the widget */
358 void
360 {
361  // if there is no viewer
362  if ( m_View )
363  {
364  // delete object
365  delete ( m_View );
366  // set pointer to NULL
367  m_View = NULL;
368  }
369 }
370 
371 //--------------------------------------------------------------------------
372 /* Create the viewer in the widget */
373 void
375 {
376  // if there is no viewer
377  if ( !HasViewer() )
378  {
379  // we create one
380  m_View = new QGoImageView3D(this);
381  dynamic_cast< QGoImageView3D * >
382  ( m_View )->setContentsMargins(1, 1, 1, 1);
383  // setup position of the widget
384  gridLayout->addWidget(m_View);
385  }
386 }
bool HasViewer(void)
true if the widget has a viewer
abstract class for QGoSynchronizedView2D and QGoSynchronizedView3D. Those classes are used to display...
QGoImageView3D * GetImageView()
int GetSynchronizedViewType(void)
returns the type of SynchronizedView (2 for 2D, 3 for 3D)
virtual void Render(void)
void SetInterpolate(const int &val)
Interpolate the data for visualization.
void SetImage(vtkImageData *iImage)
void removeSynchronizedView3D(QGoSynchronizedView3D *ioSynchronizedView)
vtkViewImage2D * GetImageViewer(const int &iId)
QString SnapshotViewXYZ(const GoFigure::FileType &iType, const QString &iBaseName=QString("snapshot-xyz-"))
QGoSynchronizedViewManager * m_ViewManager
class for the visualization of 3D Image represented by one vtkImageData*.
int GetFullScreenView() const
vtkViewImage3D * GetImageViewer3D()
QString SnapshotViewXYZ(const GoFigure::FileType &iType, const QString &iBaseName=QString("snapshot-xyz-"))
QString SnapshotViewYZ(const GoFigure::FileType &iType, const QString &iBaseName=QString("snapshot-yz-"))
QString SnapshotViewYZ(const GoFigure::FileType &iType, const QString &iBaseName=QString("snapshot-yz"))
QString SnapshotViewXY(const GoFigure::FileType &iType, const QString &iBaseName=QString("snapshot-xy-"))
virtual void SetImage(vtkImageData *iImage)
Set the image to displaid.
void SetFullScreenView(const int &iId)
void SetFullScreenView(const int &iS)
virtual void Render(void)
void Update(void)
Update the viewer contained in the widget.
QString SnapshotViewXZ(const GoFigure::FileType &iType, const QString &iBaseName=QString("snapshot-xz-"))
void Render(void)
render the all visualizations of the viewer contained in the widget if any.
QString SnapshotViewXY(const GoFigure::FileType &iType, const QString &iBaseName=tr("Snapshot-xy-"))
QGoSynchronizedView3D(QString iViewName, QWidget *iParent=0)
vtkCamera * GetCamera(void)
get the camera of the current fullscreen view
QString SnapshotViewXZ(const GoFigure::FileType &iType, const QString &iBaseName=QString("snapshot-xz-"))
void setContentsMargins(int left, int top, int right, int bottom)