GOFIGURE2  0.9.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 
37 #include "vtkImageData.h"
38 #include "vtkViewImage2D.h"
39 #include "vtkEventQtSlotConnect.h"
40 
41 #include "SnapshotHelper.h"
42 #include "QGoImageView2D.h"
44 
46 #include "itkSmartPointer.h"
47 #include "itkImage.h"
48 //--------------------------------------------------------------------------
49 /*
50 * Default Constructor.
51 * \param iSynchronizedViewName
52 * \param iParent
53 */
55  QGoSynchronizedView(iViewName, iParent),
56  m_View (NULL)
57 {
58 }
59 
60 //--------------------------------------------------------------------------
63 {
64  // remove the comparer from the manager
65  if ( m_ViewManager != NULL )
66  {
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
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
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
112 {
113  if ( m_View )
114  {
116  }
117 }
118 
119 //--------------------------------------------------------------------------
120 /* get the camera of the viewer */
121 vtkCamera *
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
140 {
141  return ( m_View != NULL );
142 }
143 
144 //--------------------------------------------------------------------------
145 /* returns the type of comparer (2 for 2D, 3 for 3D) */
146 int
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
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
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 //--------------------------------------------------------------------------
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
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 }
abstract class for QGoSynchronizedView2D and QGoSynchronizedView3D. Those classes are used to display...
void SetInterpolate(const int &val)
Interpolate the data for visualization.
void PrintOs(ostream &os)
Print self informations.
QString SnapshotViewXY(const GoFigure::FileType &iType, const QString &iBaseName=tr("Snapshot"))
Save a screenshot of the viewer's content.
vtkViewImage2D * GetImageViewer(const int &iId)
QGoSynchronizedViewManager * m_ViewManager
QString SnapshotViewXY(const GoFigure::FileType &iType, const QString &iBaseName=tr("Snapshot"))
QGoImageView2D * GetImageView(void)
Returns the imageview managed by this SynchronizedView.
virtual void Render(void)
bool HasViewer(void)
true if the widget has a viewer
QGoSynchronizedView2D(QString iViewName, QWidget *iParent=0)
void Render(void)
render the viewer contained in the widget if any
int GetSynchronizedViewType(void)
returns the type of SynchronizedView (2 for 2D, 3 for 3D)
void createViewer(void)
create the viewer contained in the widget
vtkCamera * GetCamera(void)
get the camera of the current viewer
void SetImage(vtkImageData *iImage)
Set image displayed by the SynchronizedView.
Widget to visualize a 2D image (represented as vtkImageData).
void removeSynchronizedView2D(QGoSynchronizedView2D *ioSynchronizedView)
take a QGoSynchronizedView out of the Manager lists, without deleting it.
void Update(void)
Update the viewer contained in the widget.
void setContentsMargins(int left, int top, int right, int bottom)