GOFIGURE2  0.9.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
QGoManualSegmentationSettingsDialog.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 
40 #include "vtkOrientedGlyphContourRepresentation.h"
41 #include "vtkContourWidget.h"
42 #include "vtkRenderer.h"
43 #include "vtkRenderWindow.h"
44 #include "vtkProperty.h"
45 
46 #include "vtkPolyData.h"
47 #include "vtkCellArray.h"
48 #include "vtkMath.h"
49 
51  const double & iWidth,
52  const QColor & iLineColor,
53  const QColor & iNodeColor,
54  const QColor & iActivatedNodeColor) : QDialog(
55  iParent),
56  m_LineWidth(iWidth),
57  m_LineColor(iLineColor),
58  m_NodeColor(iNodeColor),
59  m_ActivatedNodeColor(iActivatedNodeColor)
60 {
61  this->setupUi(this);
62 
63  ReadSettings();
64 
65  m_Renderer = vtkSmartPointer< vtkRenderer >::New();
66 
67  vtkRenderWindow *renwin = this->qvtkWidget->GetRenderWindow();
68  renwin->AddRenderer(m_Renderer);
69 
70  this->LineWidthSpinBox->setValue(m_LineWidth);
71 
72  m_ContourRepresentation = vtkSmartPointer< vtkOrientedGlyphContourRepresentation >::New();
73  m_ContourRepresentation->GetLinesProperty()->SetLineWidth( static_cast< float >( m_LineWidth ) );
74  m_ContourRepresentation->GetLinesProperty()->SetColor( m_LineColor.redF(),
76  m_ContourRepresentation->GetProperty()->SetColor( m_NodeColor.redF(),
78  m_ContourRepresentation->GetActiveProperty()->SetColor( m_ActivatedNodeColor.redF(),
80 
81  m_ContourWidget = vtkSmartPointer< vtkContourWidget >::New();
82  m_ContourWidget->SetInteractor( this->qvtkWidget->GetInteractor() );
83  m_ContourWidget->SetRepresentation(m_ContourRepresentation);
84  m_ContourWidget->On();
85 
86  m_InitPD = vtkSmartPointer< vtkPolyData >::New();
87  vtkSmartPointer< vtkPoints > points = vtkSmartPointer< vtkPoints >::New();
88  vtkSmartPointer< vtkCellArray > lines = vtkSmartPointer< vtkCellArray >::New();
89 
90  vtkIdType *lineIndices = new vtkIdType[7];
91 
92  for ( int i = 0; i < 6; i++ )
93  {
94  const double angle = 2.0 * vtkMath::Pi() * i / 6.0;
95  points->InsertPoint(static_cast< vtkIdType >( i ), 0.1 * cos(angle),
96  0.1 * sin(angle), 0.0);
97  lineIndices[i] = static_cast< vtkIdType >( i );
98  }
99 
100  lineIndices[6] = 0;
101  lines->InsertNextCell(7, lineIndices);
102  delete[] lineIndices;
103 
104  m_InitPD->SetPoints(points);
105  m_InitPD->SetLines(lines);
106 
107  m_ContourWidget->Initialize(m_InitPD);
108  m_ContourWidget->Render();
109  m_Renderer->ResetCamera();
110  renwin->Render();
111 
112  QObject::connect( this->LineWidthSpinBox, SIGNAL( valueChanged(double) ),
113  this, SLOT( SetLineWidth(double) ) );
114 
115  QObject::connect( this->LineColorBtn, SIGNAL( pressed() ),
116  this, SLOT( SelectLineColor() ) );
117 
118  QObject::connect( this->NodeColorBtn, SIGNAL( pressed() ),
119  this, SLOT( SelectNodeColor() ) );
120  QObject::connect( this->ActivatedNodeColorBtn, SIGNAL( pressed() ),
121  this, SLOT( SelectActivatedNodeColor() ) );
122 }
123 
126 {
127  WriteSettings();
128  delete this->qvtkWidget;
129 }
130 
131 double
133 {
134  return m_LineWidth;
135 }
136 
138 {
139  return m_LineColor;
140 }
141 
143 {
144  return m_NodeColor;
145 }
146 
148 {
149  return m_ActivatedNodeColor;
150 }
151 
153 {
154  if ( m_LineWidth != iValue )
155  {
156  m_LineWidth = iValue;
157  m_ContourRepresentation->GetLinesProperty()->SetLineWidth(
158  static_cast< float >( m_LineWidth ) );
159  m_ContourWidget->Render();
160  m_Renderer->Render();
161  }
162 }
163 
165 {
167  tr("Select Line Color") );
168 
169  if ( m_LineColor.isValid() )
170  {
171  m_ContourRepresentation->GetLinesProperty()->SetColor( m_LineColor.redF(),
173  m_ContourWidget->Render();
174  m_Renderer->Render();
175  }
176 }
177 
179 {
181  tr("Select Node Color") );
182 
183  if ( m_NodeColor.isValid() )
184  {
185  m_ContourRepresentation->GetProperty()->SetColor( m_NodeColor.redF(),
187  m_ContourWidget->Render();
188  m_Renderer->Render();
189  }
190 }
191 
193 {
195  tr("Select Activated Node Color") );
196 
198  {
199  m_ContourRepresentation->GetActiveProperty()->SetColor(
202  m_ContourWidget->Render();
203  m_Renderer->Render();
204  }
205 }
206 
208 {
209  QSettings settings;
210 
211  settings.beginGroup("ManualSegmentationSettings");
212  m_NodeColor = settings.value("NodeColor").value< QColor >();
213  m_ActivatedNodeColor = settings.value("ActivatedNodeColor").value< QColor >();
214  m_LineColor = settings.value("LineColor").value< QColor >();
215  m_LineWidth = settings.value("LineWidth").toDouble();
216 
217  if ( ( !m_NodeColor.isValid() ) && ( !m_ActivatedNodeColor.isValid() )
218  && ( !m_LineColor.isValid() ) && !( m_LineWidth > 0. ) )
219  {
220  m_LineWidth = 1.;
221  m_NodeColor = Qt::cyan;
222  m_LineColor = Qt::magenta;
223  m_ActivatedNodeColor = Qt::yellow;
224  }
225 
226  QSize tsize = settings.value("Size").toSize();
227 
228  if ( tsize.isValid() )
229  {
230  this->resize(tsize);
231  this->move( settings.value("Position").toPoint() );
232  }
233  else
234  {
235  this->resize(350, 390);
236  }
237 
238  settings.endGroup();
239 }
240 
242 {
243  QSettings settings;
244 
245  settings.beginGroup("ManualSegmentationSettings");
246  settings.setValue( "Size", this->size() );
247  settings.setValue( "Position", this->pos() );
248  settings.setValue("NodeColor", m_NodeColor);
249  settings.setValue("ActivatedNodeColor", m_ActivatedNodeColor);
250  settings.setValue("LineColor", m_LineColor);
251  settings.setValue("LineWidth", m_LineWidth);
252  settings.endGroup();
253 }
QColor GetLineColor() const
Get the color of the line.
bool isValid() const
void setupUi(QWidget *widget)
void SelectLineColor()
Open a dialog to choose the color of the lines.
qreal redF() const
void endGroup()
qreal blueF() const
T value() const
QString tr(const char *sourceText, const char *disambiguation, int n)
vtkSmartPointer< vtkContourWidget > m_ContourWidget
void setValue(const QString &key, const QVariant &value)
void resize(int w, int h)
void SelectNodeColor()
Open a dialog to choose the color of the node.
void SelectActivatedNodeColor()
Open a dialog to choose the color of the activated node.
void SetLineWidth(const double &iWidth)
Set the width of the line.
qreal greenF() const
void move(int x, int y)
QColor GetActivatedNodeColor() const
Get the color of the Active Node.
QSize toSize() const
QColor getColor(const QColor &initial, QWidget *parent, const QString &title, QFlags< QColorDialog::ColorDialogOption > options)
QVariant value(const QString &key, const QVariant &defaultValue) const
vtkSmartPointer< vtkOrientedGlyphContourRepresentation > m_ContourRepresentation
QGoManualSegmentationSettingsDialog(QWidget *parent=0, const double &iWidth=1., const QColor &iLineColor=Qt::magenta, const QColor &iNodeColor=Qt::cyan, const QColor &iActivatedNodeColor=Qt::yellow)
QPoint toPoint() const
double toDouble(bool *ok) const
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
QColor GetNodeColor() const
Get the color of the Node.
double GetLineWidth() const
Get the width of the line.
void beginGroup(const QString &prefix)
bool isValid() const