GOFIGURE2  0.9.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
QGoLUTDialog.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 
35 #include "QGoLUTDialog.h"
36 #include "QDebug"
37 #include "QColorDialog"
38 
39 #include "vtkLookupTable.h"
40 #include "vtkScalarBarActor.h"
41 #include "vtkLookupTableManager.h"
42 #include "vtkTextProperty.h"
43 #include "vtkRenderer.h"
44 #include "vtkRendererCollection.h"
45 #include "vtkRenderWindow.h"
46 
48  QDialog(iParent),
49  LUT(0)
50 {
51  setupUi(this);
52 
54  this->Renderer = vtkSmartPointer< vtkRenderer >::New();
55 
56  vtkRenderWindow *renwin = this->QvtkWidget->GetRenderWindow();
57  renwin->AddRenderer(this->Renderer);
58 
59  this->LUTActor = vtkSmartPointer< vtkScalarBarActor >::New();
60  this->LUTActor->SetLookupTable(this->LUT);
61  this->LUTActor->SetOrientationToHorizontal();
62  this->LUTActor->SetWidth(0.8);
63  this->LUTActor->SetHeight(0.9);
64  this->LUTActor->SetPosition(0.1, 0.1);
65  this->LUTActor->SetTitle("LUT");
66 
67  this->Renderer->AddActor2D(this->LUTActor);
68 
69  renwin->Render();
70 }
71 
73 {
74  // Is deleted outside
75  //this->LUT->Delete();
76  delete this->QvtkWidget;
77 }
78 
79 vtkLookupTable * QGoLUTDialog::GetLookupTable()
80 {
81  return this->LUT;
82 }
83 
84 vtkLookupTable * QGoLUTDialog::GetLookupTable(QWidget *iiParent,
85  const QString & iTitle,
86  const int & iIdx)
87 {
88  QGoLUTDialog dlg(iiParent);
89 
90  if ( !iTitle.isEmpty() )
91  {
92  dlg.setWindowTitle(iTitle);
93  }
94  dlg.ChangeLookupTable(iIdx);
95  if ( dlg.exec() == QDialog::Accepted )
96  {
97  return dlg.GetLookupTable();
98  }
99  else
100  {
101  dlg.GetLookupTable()->Delete();
102  return NULL;
103  }
104 }
105 
107 {
108  if ( LUTDialog->objectName().isEmpty() )
109  {
110  LUTDialog->setObjectName( QString::fromUtf8("LUTDialog") );
111  }
112 
113  LUTDialog->resize(321, 183);
114  LUTDialog->setMinimumSize(200, 150);
115  LUTDialog->setModal(true);
116 
117  this->VerticalLayout = new QVBoxLayout(LUTDialog);
118  this->VerticalLayout->setObjectName( QString::fromUtf8("VerticalLayout") );
119  this->VerticalLayout->setContentsMargins(10, 10, 10, 10);
120  this->VerticalLayout->setSpacing(20);
121 
122  this->HorizontalLayout = new QHBoxLayout;
123  this->HorizontalLayout->setObjectName( QString::fromUtf8("HorizontalLayout") );
124  this->HorizontalLayout->setContentsMargins(0, 0, 0, 0);
125 
126  this->Label = new QLabel;
127  this->Label->setObjectName( QString::fromUtf8("Label") );
128  this->Label->setText( tr("Lookup Table") );
129 
131 
132  this->LUTComboBox = new QComboBox;
133  this->LUTComboBox->setObjectName( QString::fromUtf8("LUTComboBox") );
134  this->LUTComboBox->setLayoutDirection(Qt::RightToLeft);
135  this->LUTComboBox->setAutoFillBackground(false);
136  this->LUTComboBox->setEditable(false);
137  this->LUTComboBox->setFrame(true);
138 
139  std::vector< std::string > lut_names =
141 
142  size_t k = 0;
143  for (; k < lut_names.size(); k++ )
144  {
145  this->LUTComboBox->insertItem( static_cast< int >( k ), QString::fromStdString(lut_names[k]) );
146  }
147  this->LUTComboBox->insertItem( static_cast< int >( k ), tr("HSV Based") );
148 
149  this->HorizontalLayout->addWidget(this->LUTComboBox);
150 
152 
153  this->QvtkWidget = new QVTKWidget;
154  this->QvtkWidget->setObjectName( QString::fromUtf8("qvtkWidget") );
155  this->QvtkWidget->setGeometry( QRect(10, 50, 301, 100) );
156 
157  this->VerticalLayout->addWidget(this->QvtkWidget);
158 
159  this->HorizontalLayout_2 = new QHBoxLayout;
160  this->HorizontalLayout_2->setObjectName( QString::fromUtf8("horizontalLayout_2") );
161  this->HorizontalLayout_2->setContentsMargins(0, 0, 0, 0);
162 
163  this->HorizontalSpacer = new QSpacerItem(166, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
165 
166  this->ButtonBox = new QDialogButtonBox;
167  this->ButtonBox->setObjectName( QString::fromUtf8("buttonBox") );
168  this->ButtonBox->setGeometry( QRect(60, 160, 252, 32) );
169  this->ButtonBox->setOrientation(Qt::Horizontal);
170  this->ButtonBox->setStandardButtons(QDialogButtonBox::Cancel
171  | QDialogButtonBox::Ok);
172  this->ButtonBox->setCenterButtons(false);
174 
176 
177  LUTDialog->setLayout(this->VerticalLayout);
178 
179  QObject::connect( this->ButtonBox, SIGNAL( accepted() ),
180  LUTDialog, SLOT( accept() ) );
181  QObject::connect( this->ButtonBox, SIGNAL( rejected() ),
182  LUTDialog, SLOT( reject() ) );
183  QObject::connect( this->LUTComboBox, SIGNAL( currentIndexChanged(int) ),
184  this, SLOT( ChangeLookupTable(int) ) );
185 
187 
189 }
190 
191 void QGoLUTDialog::ChangeLookupTable(const int & idx)
192 {
193  this->LUT->Delete();
194  int N = this->LUTComboBox->count();
195 
196  if ( ( idx >= N ) || ( idx < 0 ) )
197  {
198  qWarning() << "QGoLUTDialog idx is out of range";
199  return;
200  }
201  else
202  {
203  if ( idx == N - 1 )
204  {
205  QColor color = QColorDialog::getColor(Qt::green);
206 
207  double hsv[3];
208 
209  if ( color.isValid() )
210  {
211  hsv[0] = color.hueF();
212  hsv[1] = color.saturationF();
213  hsv[2] = color.valueF();
214  }
215  else
216  {
217  color = Qt::green;
218  hsv[0] = color.hueF();
219  hsv[1] = color.saturationF();
220  hsv[2] = color.valueF();
221  }
222 
224  }
225  else
226  {
228  }
229 
230  this->LUTActor->SetLookupTable(this->LUT);
231  this->QvtkWidget->GetRenderWindow()->Render();
232  }
233 }
static vtkLookupTable * GetLookupTable(const int &iIndex)
Get the indexed lookup table.
void setContentsMargins(int left, int top, int right, int bottom)
virtual void reject()
void setModal(bool modal)
QComboBox * LUTComboBox
Definition: QGoLUTDialog.h:93
QGoLUTDialog(QWidget *parent=0)
Constructor.
vtkSmartPointer< vtkScalarBarActor > LUTActor
Definition: QGoLUTDialog.h:84
QDialogButtonBox * ButtonBox
Definition: QGoLUTDialog.h:86
Look-up Table Dialog.
Definition: QGoLUTDialog.h:60
void rejected()
void accepted()
static vtkLookupTable * GetHSVBasedLookupTable(double iRGB[3])
Get one HSV based lookup table.
int exec()
void setEditable(bool editable)
vtkSmartPointer< vtkRenderer > Renderer
Definition: QGoLUTDialog.h:85
QString tr(const char *sourceText, const char *disambiguation, int n)
static vtkLookupTable * GetBWLookupTable(void)
Get the BW lookup table.
void insertItem(int index, const QString &text, const QVariant &userData)
void setGeometry(int x, int y, int w, int h)
void resize(int w, int h)
void setMinimumSize(const QSize &)
void addWidget(QWidget *widget, int stretch, QFlags< Qt::AlignmentFlag > alignment)
virtual ~QGoLUTDialog()
Destructor.
QString fromStdString(const std::string &str)
QString fromUtf8(const char *str, int size)
void setLayout(QLayout *layout)
void setLayoutDirection(Qt::LayoutDirection direction)
QLabel * Label
Definition: QGoLUTDialog.h:92
qreal valueF() const
vtkLookupTable * GetLookupTable()
get the selected look up table
virtual void addItem(QLayoutItem *item)
bool isEmpty() const
void setText(const QString &)
virtual void accept()
void ChangeLookupTable(const int &)
Change look up table.
vtkLookupTable * LUT
Definition: QGoLUTDialog.h:83
QColor getColor(const QColor &initial, QWidget *parent, const QString &title, QFlags< QColorDialog::ColorDialogOption > options)
QVTKWidget * QvtkWidget
Definition: QGoLUTDialog.h:87
qreal saturationF() const
qreal hueF() const
QHBoxLayout * HorizontalLayout
Definition: QGoLUTDialog.h:88
QSpacerItem * HorizontalSpacer
Definition: QGoLUTDialog.h:91
void setCenterButtons(bool center)
void setStandardButtons(QFlags< QDialogButtonBox::StandardButton > buttons)
void setWindowTitle(const QString &)
void setCurrentIndex(int index)
void setOrientation(Qt::Orientation orientation)
void setAutoFillBackground(bool enabled)
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
void setupUi(QDialog *LUTDialog)
void setFrame(bool)
QVBoxLayout * VerticalLayout
Definition: QGoLUTDialog.h:90
QHBoxLayout * HorizontalLayout_2
Definition: QGoLUTDialog.h:89
void connectSlotsByName(QObject *object)
void setSpacing(int spacing)
bool isValid() const
void addLayout(QLayout *layout, int stretch)
static std::vector< std::string > GetAvailableLookupTables(void)
Get the available lookup table.