GOFIGURE2  0.9.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
QGoTabImageView2D.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 "QGoTabImageView2D.h"
35 
36 #include "QGoImageView2D.h"
37 #include "QGoLUTDialog.h"
39 
40 #include "vtkLookupTable.h"
41 #include "vtkEventQtSlotConnect.h"
42 #include "vtkRenderWindow.h"
43 #include "vtkRendererCollection.h"
44 #include "vtkImageData.h"
45 #include "vtkTextProperty.h"
46 #include "vtkImageExtractComponents.h"
47 #include "vtkProperty.h"
48 #include "vtkContourWidget.h"
49 #include "vtkOrientedGlyphContourRepresentation.h"
50 #include "vtkImageActorPointPlacer.h"
51 
53 
54 #include <QCursor>
55 #include <QMenu>
56 #include <QColorDialog>
57 #include <QMessageBox>
58 #include <QSettings>
59 #include <QVariant>
60 
61 //--------------------------------------------------------------------------
63  QGoTabImageViewNDBase(iParent)
64 {
65  m_Image = 0;
66  setupUi(this);
67 
68  this->m_ContourRepresentation.push_back(
69  vtkSmartPointer< vtkOrientedGlyphContourRepresentation >::New() );
70  this->m_ContourRepresentation.back()->GetProperty()->SetColor(0., 1., 1.);
71  this->m_ContourRepresentation.back()->GetLinesProperty()->SetColor(1., 0., 1.);
72  this->m_ContourRepresentation.back()->GetActiveProperty()->SetColor(1., 1., 0.);
73 
74  this->m_ContourWidget.push_back(
75  vtkSmartPointer< vtkContourWidget >::New() );
76  this->m_ContourWidget.back()->SetPriority(10.0);
77  this->m_ContourWidget.back()->SetInteractor( m_ImageView->GetInteractor() );
78  this->m_ContourWidget.back()->Off();
79 
81  m_NavigationDockWidget->resize(120, 300);
82 
83  this->m_DockWidgetList.push_front(
84  std::pair< QGoDockWidgetStatus *, QDockWidget * >(
85  new QGoDockWidgetStatus(m_NavigationDockWidget, Qt::LeftDockWidgetArea, true, true),
87 
88  QAction *LookupTableAction = new QAction(tr("Lookup Table"), this);
89  LookupTableAction->setStatusTip( tr(" Change the associated lookup table") );
90 
91  QIcon luticon;
92  luticon.addPixmap(QPixmap( QString::fromUtf8(":/fig/LookupTable.png") ),
93  QIcon::Normal, QIcon::Off);
94  LookupTableAction->setIcon(luticon);
95 
96  // Here write the connection
97  QObject::connect( LookupTableAction, SIGNAL( triggered() ),
98  this, SLOT( ChangeLookupTable() ) );
99 
100  this->m_ViewActions.push_back(LookupTableAction);
101 
102  QAction *ScalarBarAction = new QAction(tr("Display Scalar Bar"), this);
103  ScalarBarAction->setCheckable(true);
104 
105  QIcon scalarbaricon;
106  scalarbaricon.addPixmap(QPixmap( QString::fromUtf8(":/fig/scalarbar.png") ),
107  QIcon::Normal, QIcon::Off);
108  ScalarBarAction->setIcon(scalarbaricon);
109 
110  this->m_ViewActions.push_back(ScalarBarAction);
111 
112  QObject::connect( ScalarBarAction, SIGNAL( toggled(bool) ),
113  this, SLOT( ShowScalarBar(bool) ) );
114 
115  QPixmap Pix(16, 16);
116  Pix.fill(Qt::black);
117  m_BackgroundColorAction = new QAction(Pix, tr("Set Background Color"), this);
118  this->m_ViewActions.push_back(m_BackgroundColorAction);
119 
120  QObject::connect( m_BackgroundColorAction, SIGNAL( triggered() ),
121  this, SLOT( ChangeBackgroundColor() ) );
122 
123  QObject::connect( m_NavigationDockWidget, SIGNAL( ShowAllChannelsChanged(bool) ),
124  this, SLOT( ShowAllChannels(bool) ) );
125 
126  QObject::connect( m_NavigationDockWidget, SIGNAL( ShowOneChannelChanged(int) ),
127  this, SLOT( ShowOneChannel(int) ) );
128 
129  QAction *separator2 = new QAction(this);
130  separator2->setSeparator(true);
131  this->m_ViewActions.push_back(separator2);
132 
134 
135  //CreateModeActions();
136 
137  ReadSettings();
138 }
139 
140 //--------------------------------------------------------------------------
141 
142 //--------------------------------------------------------------------------
145 {
146 }
147 
148 //--------------------------------------------------------------------------
149 
150 //--------------------------------------------------------------------------
153 {
154  return GoFigure::TWO_D;
155 }
156 
157 //--------------------------------------------------------------------------
158 
159 //--------------------------------------------------------------------------
160 void
162 {
163  if ( iParent->objectName().isEmpty() )
164  {
165  iParent->resize(800, 800);
166  }
167 
168  m_ImageView = new QGoImageView2D(this);
171 
172  retranslateUi(iParent);
173 
175 } // setupUi
176 
177 //--------------------------------------------------------------------------
178 
179 //--------------------------------------------------------------------------
180 void
182 {
183  iParent->setWindowTitle( tr("QGoTabImageView2D") );
184  Q_UNUSED(iParent);
185 }
186 
187 //--------------------------------------------------------------------------
188 
189 //--------------------------------------------------------------------------
190 void
192 {
193  m_ImageView->Update();
194 }
195 
196 //--------------------------------------------------------------------------
197 
198 //--------------------------------------------------------------------------
199 void
201 {
203 }
204 
205 //--------------------------------------------------------------------------
206 
207 //--------------------------------------------------------------------------
208 void
210 {
211  double r(0.), g(0.), b(0.);
212 
214  this->m_BackgroundColor.setRgbF(r, g, b);
215 }
216 
217 //--------------------------------------------------------------------------
218 
219 //--------------------------------------------------------------------------
220 void
222 {
223  vtkLookupTable *lut = vtkLookupTable::New();
224 
225  lut->DeepCopy( QGoLUTDialog::GetLookupTable( this,
226  tr("Choose one look-up table") ) );
228  lut->Delete();
229 }
230 
231 //--------------------------------------------------------------------------
232 
233 //--------------------------------------------------------------------------
234 void
236 {
237  m_ImageView->ShowScalarBar(iShow);
238 }
239 
240 //--------------------------------------------------------------------------
241 
242 //--------------------------------------------------------------------------
243 void
245 {
247 }
248 
249 //--------------------------------------------------------------------------
250 
251 //--------------------------------------------------------------------------
252 void
254 {
256 }
257 
258 //--------------------------------------------------------------------------
259 
260 //--------------------------------------------------------------------------
261 void
263 {
264  m_ImageView->SetImage(iImage);
265  m_ImageView->Update();
266 
267  vtkImageActorPointPlacer *point_placer = vtkImageActorPointPlacer::New();
268  point_placer->SetImageActor( m_ImageView->GetImageActor(0) );
269 
270  this->m_ContourRepresentation.back()->SetPointPlacer(point_placer);
271  point_placer->Delete();
272 
273  this->m_ContourWidget.back()->SetRepresentation(
274  this->m_ContourRepresentation.back() );
275 }
276 
277 //--------------------------------------------------------------------------
278 
279 //--------------------------------------------------------------------------
280 int *
282 {
284 }
285 
286 //--------------------------------------------------------------------------
287 
288 //--------------------------------------------------------------------------
289 // std::vector< vtkQuadricLODActor* >
290 std::vector< vtkActor * >
291 QGoTabImageView2D::AddContour(vtkPolyData *dataset, vtkProperty *iProperty)
292 {
293  return m_ImageView->AddContour(dataset, iProperty);
294 }
295 
296 //--------------------------------------------------------------------------
297 
298 //--------------------------------------------------------------------------
299 void
300 QGoTabImageView2D::RemoveActorFromViewer(const int & iId, vtkActor *iActor)
301 {
302  m_ImageView->RemoveActor(iId, iActor);
303 }
304 
305 //--------------------------------------------------------------------------
306 
307 //--------------------------------------------------------------------------
308 void
309 QGoTabImageView2D::DisplayActorInViewer(const int & iId, vtkActor *iActor)
310 {
311  m_ImageView->AddActor(iId, iActor);
312 }
313 
314 //--------------------------------------------------------------------------
315 
316 //--------------------------------------------------------------------------
317 void
318 QGoTabImageView2D::SetSlice(int iDir, int *iIdx)
319 {
320  (void)iDir;
321  (void)iIdx;
322 }
323 
324 //-------------------------------------------------------------------------
325 
326 //-------------------------------------------------------------------------
327 void
329 {
330  double r(0.), g(0.), b(0.);
331 
333  m_BackgroundColor.setRgbF(r, g, b);
334 
336  this, tr("Choose Background Color") );
337 
338  if ( temp != m_BackgroundColor )
339  {
340  m_BackgroundColor = temp;
342  QPixmap Pix(16, 16);
343  Pix.fill(temp);
345  }
346 }
347 
348 //-------------------------------------------------------------------------
349 
350 //-------------------------------------------------------------------------
352 {
353  //QActionGroup *group = new QActionGroup(this);
354 
355  // Call superclass
356  //QGoTabElementBase::CreateModeActions(group);
357  QGoTabElementBase::CreateModeToolBar(iMenu, iToolBar);
358  this->m_ToolBarList.push_back(this->m_ModeToolBar);
359 }
360 
361 //-------------------------------------------------------------------------
362 
363 //-------------------------------------------------------------------------
364 void
366 {
368 }
369 
370 //-------------------------------------------------------------------------
371 void
373 {
374  (void)iEnable;
376 }
377 
378 //-------------------------------------------------------------------------
379 
380 //-------------------------------------------------------------------------
381 void
383 {
384  (void)iEnable;
386 }
387 
388 //-------------------------------------------------------------------------
389 
390 //-------------------------------------------------------------------------
391 void
393 {
394  (void)iEnable;
395  m_ImageView->PanMode();
396 }
QAction * toggleViewAction()
std::vector< vtkActor * > AddContour(vtkPolyData *dataset, vtkProperty *property=NULL)
GoFigure::TabDimensionType GetTabDimensionType() const
Get the dimension type of the underlying data set.
void SetBackgroundColorToImageViewer()
void SetImage(vtkImageData *iImage)
Set the image to displaid.
QGoTabImageView2D(QWidget *parent=0)
void setSeparator(bool b)
void setRgbF(qreal r, qreal g, qreal b, qreal a)
void fill(const QColor &color)
std::vector< vtkSmartPointer< vtkContourWidget > > m_ContourWidget
void setupUi(QWidget *parent)
std::list< QGoDockWidgetStatusPair > m_DockWidgetList
void GetBackgroundColor(double &r, double &g, double &b)
Returns used background color by viewers.
void setIcon(const QIcon &icon)
virtual void AddActor(const int &iId, vtkActor *iActor)
void ShowScalarBar(const bool &)
Show/hide the scalar bar in the collection.
vtkSmartPointer< vtkImageData > m_Image
void PanMode()
Use the pan interactor style.
void ShowOneChannel(int iChannel)
virtual void RemoveActorFromViewer(const int &iId, vtkActor *iActor)
QString tr(const char *sourceText, const char *disambiguation, int n)
virtual void SetSlice(int iDir, int *iIdx)
void GetBackgroundColorFromImageViewer()
QAction * m_BackgroundColorAction
void SetLookupTable(vtkLookupTable *iLut)
Set the lookup table in the collection.
virtual void DisplayActorInViewer(const int &iId, vtkActor *iActor)
void resize(int w, int h)
void CreateModeToolBar(QMenu *iMenu, QToolBar *iToolBar)
QString fromUtf8(const char *str, int size)
virtual void PanInteractorBehavior(bool)
Mouse interaction style allows user to pan volume with all buttons.
virtual void CreateModeToolBar(QMenu *iMenu, QToolBar *iToolBar)
vtkLookupTable * GetLookupTable()
get the selected look up table
void ZoomMode()
Use the zoom interactor style.
QString SnapshotViewXY(const GoFigure::FileType &iType, const QString &iBaseName=tr("Snapshot"))
void addPixmap(const QPixmap &pixmap, Mode mode, State state)
virtual void DefaultInteractorBehavior(bool)
Mouse interaction style set as default.
void setCentralWidget(QWidget *widget)
Dock Widget for browsing images (changing slice, time point...)
virtual void Update()
Update the rendering of the tab.
QColor getColor(const QColor &initial, QWidget *parent, const QString &title, QFlags< QColorDialog::ColorDialogOption > options)
std::list< QGoToolBarStatus * > m_ToolBarList
void setCheckable(bool)
virtual void ReadSettings()
Read Settings.
QVTKInteractor * GetInteractor(const int &i=0)
Returns the interactor for one given view.
Abstract class for representing one tab element which contains 2D or 3D image (without any temporal c...
virtual void ReadSettings()
Read Settings.
void retranslateUi(QWidget *parent)
virtual std::vector< vtkActor * > AddContour(vtkPolyData *iDataset, vtkProperty *iProperty=NULL)
Add contour with given property into the visualization.
void setStatusTip(const QString &statusTip)
int * GetImageCoordinatesFromWorldCoordinates(double pos[3])
Get Image Coordinates from World Coordinates.
virtual void WriteSettings()
Write Settings.
int * GetImageCoordinatesFromWorldCoordinates(double pos[3])
QGoNavigationDockWidget * m_NavigationDockWidget
void setWindowTitle(const QString &)
std::vector< QAction * > m_ViewActions
virtual void WriteSettings()
Write Settings.
void ShowScalarBar(const bool &)
void SetImageToImageViewer(vtkImageData *image)
std::vector< vtkSmartPointer< vtkOrientedGlyphContourRepresentation > > m_ContourRepresentation
Widget to visualize a 2D image (represented as vtkImageData).
vtkImageActor * GetImageActor(const int &iId)
Get the image actor.
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
virtual void ZoomInteractorBehavior(bool)
Mouse interaction style allows user to zoom in/out volume with all buttons.
void SetBackgroundColor(const double &r, const double &g, const double &b)
Set background color for all views.
void ShowAllChannels(bool iChecked)
QGoImageView2D * m_ImageView
virtual void RemoveActor(const int &iId, vtkActor *iActor)
void connectSlotsByName(QObject *object)
void DefaultMode()
Use the default interactor style.
QGoToolBarStatus * m_ModeToolBar