GOFIGURE2  0.9.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
QGoTabImageViewElementBase.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 
36 
37 #include <QColorDialog>
38 #include <QSettings>
39 #include <iostream>
40 
41 #include "vtkContourWidget.h"
42 #include "vtkOrientedGlyphContourRepresentation.h"
43 #include "vtkImageActorPointPlacer.h"
44 #include "vtkPolyData.h"
45 #include "vtkActor.h"
46 #include "vtkProperty.h"
47 
48 #include "ContourContainer.h"
49 #include "MeshContainer.h"
50 
53 
54 //--------------------------------------------------------------------------
60  QGoTabElementBase(iParent),
61  m_Color(false),
62  m_BackgroundColor(Qt::black),
63  m_ContourId(0),
64  m_ReEditContourMode(false),
65  m_NavigationDockWidget(0)
66 {
68  m_ContourContainer = new ContourContainer(this, NULL);
69  m_MeshContainer = new MeshContainer(this, NULL);
70 
72 
74 
76  //m_DockWidgetList.push_back(
77  // std::pair<QGoDockWidgetStatus*, QDockWidget*>(
78  // new QGoDockWidgetStatus(m_ManualSegmentationWidget,
79  // Qt::LeftDockWidgetArea, true, true),
80  // m_ManualSegmentationWidget));
81 }
82 
83 //--------------------------------------------------------------------------
84 
85 //--------------------------------------------------------------------------
90 {
91 }
92 
93 //--------------------------------------------------------------------------
94 
95 //-------------------------------------------------------------------------
99 void
101 {
103 
104  QObject::connect( m_ManualSegmentationWidget, SIGNAL( ValidatePressed() ),
105  this, SLOT( ValidateContour() ) );
106 
107  QObject::connect( m_ManualSegmentationWidget, SIGNAL( ReinitializePressed() ),
108  this, SLOT( ReinitializeContour() ) );
109 
111  SIGNAL( UpdateContourRepresentationProperties() ),
112  this, SLOT( ChangeContourRepresentationProperty() ) );
113 
114 // QAction* tempaction = m_ManualSegmentationWidget->toggleViewAction();
115 
116 // this->m_SegmentationActions.push_back(tempaction);
117 }
118 
119 //-------------------------------------------------------------------------
120 
121 //-------------------------------------------------------------------------
122 void
124 {
125  float linewidth = static_cast< float >( m_LinesWidth );
126  QColor linecolor = m_LinesColor;
127  QColor nodecolor = m_NodesColor;
128  QColor activenodecolor = m_ActiveNodesColor;
129 
130  qreal rl, gl, bl;
131  linecolor.getRgbF(&rl, &gl, &bl);
132 
133  qreal rn, gn, bn;
134  nodecolor.getRgbF(&rn, &gn, &bn);
135 
136  qreal ra, ga, ba;
137  activenodecolor.getRgbF(&ra, &ga, &ba);
138 
139  for ( unsigned int i = 0; i < m_ContourRepresentation.size(); i++ )
140  {
141  m_ContourRepresentation[i]->GetLinesProperty()->SetLineWidth(linewidth);
142  m_ContourRepresentation[i]->GetLinesProperty()->SetColor(
143  static_cast< double >( rl ),
144  static_cast< double >( gl ),
145  static_cast< double >( bl ) );
146 
147  m_ContourRepresentation[i]->GetProperty()->SetColor(
148  static_cast< double >( rn ),
149  static_cast< double >( gn ),
150  static_cast< double >( bn ) );
151  m_ContourRepresentation[i]->GetActiveProperty()->SetColor(
152  static_cast< double >( ra ),
153  static_cast< double >( ga ),
154  static_cast< double >( ba ) );
155  }
156 }
157 
158 //-------------------------------------------------------------------------
159 
160 //--------------------------------------------------------------------------
165 void QGoTabImageViewElementBase::SetColor(const bool & iColor)
166 {
167  m_Color = iColor;
168 }
169 
170 //--------------------------------------------------------------------------
171 
172 //--------------------------------------------------------------------------
178 {
179  QSettings settings;
180 
181  settings.beginGroup("QGoTabImageViewElementBase");
182  settings.setValue("BackgroundColor", m_BackgroundColor);
183  settings.endGroup();
184 }
185 
186 //--------------------------------------------------------------------------
187 
188 //--------------------------------------------------------------------------
194 {
195  QSettings settings;
196 
197  settings.beginGroup("QGoTabImageViewElementBase");
198  QVariant var = settings.value("BackgroundColor");
199  m_BackgroundColor = var.value< QColor >();
200 
202 
203  settings.endGroup();
204 }
205 
206 //--------------------------------------------------------------------------
207 
208 //--------------------------------------------------------------------------
213 {
215 
217  this, tr("Choose Background Color") );
218 
219  if ( temp.isValid() )
220  {
221  if ( temp != m_BackgroundColor )
222  {
223  m_BackgroundColor = temp;
225  }
226  }
227 }
228 
229 //--------------------------------------------------------------------------
230 
231 //--------------------------------------------------------------------------
237 {
238  std::vector< vtkSmartPointer< vtkContourWidget > >::iterator it =
239  m_ContourWidget.begin();
240  while ( it != m_ContourWidget.end() )
241  {
242  if ( iActivate )
243  {
244  ( *it )->On();
245  }
246  else
247  {
248  ( *it )->Off();
249  }
250  ++it;
251  }
252 }
253 
254 //--------------------------------------------------------------------------
255 
256 //--------------------------------------------------------------------------
262 {
263  vtkPolyData *contour =
264  m_ContourRepresentation[iId]->GetContourRepresentationAsPolyData();
265 
266  // get color from the dock widget
267  double r, g, b, a;
268 
269  r = 0.1;
270  g = 0.5;
271  b = 0.7;
272  a = 1.;
273 
274  vtkProperty *contour_property = vtkProperty::New();
275  contour_property->SetRepresentationToWireframe();
276  contour_property->SetColor(r, g, b);
277  contour_property->SetOpacity(a);
278 
279  // Compute Bounding Box
280  double bounds[6];
281  contour->GetBounds(bounds);
282 
283  // Extract Min and Max from bounds
284  /* double Min[3];
285  double Max[3];
286  int k = 0;
287  for ( int i = 0; i < 3; ++i )
288  {
289  Min[i] = bounds[k++];
290  Max[i] = bounds[k++];
291  }*/
292 
293 // *** Get the Bounding Box ***
294 // int* min_idx = this->GetImageCoordinatesFromWorldCoordinates( Min );
295 // int* max_idx = this->GetImageCoordinatesFromWorldCoordinates( Max );
296 // (void) min_idx;
297 // (void) max_idx;
298 // ****************************
299 
300  vtkPolyData *contour_nodes = vtkPolyData::New();
301  m_ContourRepresentation[iId]->GetNodePolyData(contour_nodes);
302 
303  // get corresponding actor from visualization
304  vtkPolyData *contour_copy = vtkPolyData::New();
305  contour_copy->ShallowCopy(contour);
306 
307 // std::vector< vtkQuadricLODActor* > contour_actor =
308  std::vector< vtkActor * > contour_actor =
309  this->AddContour(contour_copy,
310  contour_property);
311 
312  contour_copy->Delete();
313  contour_property->Delete();
314 
316 
317 // // get meshid from the dock widget (SpinBox)
318 // // unsigned int meshid = m_ManualSegmentationWidget->GetMeshId();
319 // unsigned int meshid = 0;
320 //
321 // if( this->m_NavigationDockWidget->GetCurrentCollectionID() != -1 )
322 // {
323 // meshid =
324 // static_cast< unsigned int >(
325 // this->m_NavigationDockWidget->GetCurrentCollectionID() );
326 // }
327 //
328 // unsigned int timepoint = 0;
329 // bool highlighted = false;
330 //
331 // // fill the container
332 //
333 // for( unsigned int i = 0; i < contour_actor.size(); i++ )
334 // {
335 // ContourMeshStructure temp( m_ContourId, contour_actor[i], contour_nodes,
336 // meshid,
337 // timepoint, highlighted, r, g, b, alpha, i );
338 // m_ContourMeshContainer.insert( temp );
339 // }
340 //
341 // m_ContourId++;
342 }
343 
344 //--------------------------------------------------------------------------
345 
346 //--------------------------------------------------------------------------
351 {
352  for ( unsigned int i = 0; i < m_ContourWidget.size(); i++ )
353  {
354  ValidateContour(i);
355  }
356 }
357 
358 //--------------------------------------------------------------------------
359 
360 //--------------------------------------------------------------------------
365 void
367 {
369  it = m_ContourContainer->m_Container.get< TraceID >().find(iId);
370 
371  if ( it != m_ContourContainer->m_Container.get< TraceID >().end() )
372  {
373  vtkPolyData *c_nodes = NULL;
374 
376 // c_dir = (*it).Direction;
377 // c_actor = (*it).Actor;
378 // c_nodes = (*it).Nodes;
379 //
380 // RemoveActorFromViewer(c_dir, c_actor);
381 
382  m_ContourContainer->m_Container.erase(iId);
383 
384  if ( m_ContourWidget.size() > 1 )
385  {
386  int dir =
388 
389  if ( dir != -1 )
390  {
391  m_ReEditContourMode = true;
392  m_ContourId = iId;
393 
394  double p[3];
395  c_nodes->GetPoint(0, p);
396  int *idx = this->GetImageCoordinatesFromWorldCoordinates(p);
397  this->SetSlice(dir, idx);
398 
399  delete[] idx;
400 
401  m_ContourWidget[dir]->Initialize(c_nodes);
403  }
404  }
405  else
406  {
407  m_ContourWidget[0]->Initialize(c_nodes);
409  }
410  }
411 }
412 
413 //--------------------------------------------------------------------------
414 
415 //-------------------------------------------------------------------------
416 void
418 {
419  for ( unsigned int i = 0; i < m_ContourWidget.size(); i++ )
420  {
423  m_ContourWidget[i]->Initialize(NULL);
424  }
425 }
426 
427 //-------------------------------------------------------------------------
428 
429 //-------------------------------------------------------------------------
430 void
432 {
433  m_TakeSnapshotAction = new QAction(tr("Take Snapshot"), this);
434  QIcon snapshoticon;
435  snapshoticon.addPixmap(QPixmap( QString::fromUtf8(":/fig/camera-photo.png") ),
436  QIcon::Normal, QIcon::Off);
437  m_TakeSnapshotAction->setIcon(snapshoticon);
438  m_TakeSnapshotAction->setStatusTip( tr("You have to be in full screen view to use the snapshot") );
440 
441  QObject::connect( m_TakeSnapshotAction, SIGNAL( triggered() ),
442  this, SLOT( TakeSnapshot() ) );
443 
444  this->m_ToolsActions.push_back(m_TakeSnapshotAction);
445 }
446 
447 //-------------------------------------------------------------------------
Abstract class for one tab element in GoFigure2.
virtual void SetBackgroundColorToImageViewer()=0
virtual void SetColor(const bool &iColor)
virtual void TakeSnapshot()=0
std::vector< vtkSmartPointer< vtkContourWidget > > m_ContourWidget
void endGroup()
void setIcon(const QIcon &icon)
virtual int * GetImageCoordinatesFromWorldCoordinates(double pos[3])=0
void ReEditContour(const unsigned int &iId)
Re-edit the iId^th contour.
MultiIndexContainerType::template index< TraceID >::type::iterator MultiIndexContainerTraceIDIterator
T value() const
MultiIndexContainerType m_Container
Trace Contaienr.
void getRgbF(qreal *r, qreal *g, qreal *b, qreal *a) const
QString tr(const char *sourceText, const char *disambiguation, int n)
void setValue(const QString &key, const QVariant &value)
void setEnabled(bool)
QString fromUtf8(const char *str, int size)
virtual void ValidateContour()
Validate contour traced in the ContourWidget.
static int ComputeDirectionFromContour(vtkPolyData *iContour)
Returns the direction of a given contour vtkPolyData. This static method is supposed to be used when ...
Wraps a boost::multi_index_container of ContourMeshStructure. This class is specialized for the means...
void ActivateManualSegmentationEditor(const bool &iActivate)
Activate the manual segmentation editor (ContourWidget).
void addPixmap(const QPixmap &pixmap, Mode mode, State state)
std::vector< QAction * > m_ToolsActions
void ReinitializeContour()
Reinitialize contour in the ContourWidget (delete contour, and restart with no contours.
QColor getColor(const QColor &initial, QWidget *parent, const QString &title, QFlags< QColorDialog::ColorDialogOption > options)
virtual void GetBackgroundColorFromImageViewer()=0
QVariant value(const QString &key, const QVariant &defaultValue) const
virtual void ReadSettings()
Read Settings.
void setStatusTip(const QString &statusTip)
virtual void WriteSettings()
Write Settings.
void ChangeBackgroundColor()
Change the background color.
Wraps a boost::multi_index_container of ContourMeshStructure. This class is specialized for the means...
Definition: MeshContainer.h:46
QWidget * find(WId id)
QGoContourManualSegmentationWidget * m_ManualSegmentationWidget
std::vector< vtkSmartPointer< vtkOrientedGlyphContourRepresentation > > m_ContourRepresentation
virtual void SetSlice(int iDir, int *iIdx)=0
QGoTabImageViewElementBase(QWidget *parent=0)
Constructor.
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
virtual std::vector< vtkActor * > AddContour(vtkPolyData *dataset, vtkProperty *property=NULL)=0
virtual ~QGoTabImageViewElementBase()
Destructor.
void ChangeContourRepresentationProperty()
Change contour representation property (color, line width, etc.)
Define the manual segmentation widget connections.
void setEnabled(bool)
void beginGroup(const QString &prefix)
bool isValid() const