GOFIGURE2  0.9.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
GoTransferFunctionWidget.cxx
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
6 **
7 ** This file is part of the demonstration applications of the Qt Toolkit.
8 **
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** Commercial Usage
11 ** Licensees holding valid Qt Commercial licenses may use this file in
12 ** accordance with the Qt Commercial License Agreement provided with the
13 ** Software or, alternatively, in accordance with the terms contained in
14 ** a written agreement between you and Nokia.
15 **
16 ** GNU Lesser General Public License Usage
17 ** Alternatively, this file may be used under the terms of the GNU Lesser
18 ** General Public License version 2.1 as published by the Free Software
19 ** Foundation and appearing in the file LICENSE.LGPL included in the
20 ** packaging of this file. Please review the following information to
21 ** ensure the GNU Lesser General Public License version 2.1 requirements
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
23 **
24 ** In addition, as a special exception, Nokia gives you certain additional
25 ** rights. These rights are described in the Nokia Qt LGPL Exception
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
27 **
28 ** GNU General Public License Usage
29 ** Alternatively, this file may be used under the terms of the GNU
30 ** General Public License version 3.0 as published by the Free Software
31 ** Foundation and appearing in the file LICENSE.GPL included in the
32 ** packaging of this file. Please review the following information to
33 ** ensure the GNU General Public License version 3.0 requirements will be
34 ** met: http://www.gnu.org/copyleft/gpl.html.
35 **
36 ** If you have questions regarding the use of this file, please contact
37 ** Nokia at qt-info@nokia.com.
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 /*=========================================================================
43  Modifications were made by the GoFigure Dev. Team.
44  while at Megason Lab, Systems biology, Harvard Medical school, 2009-11
45 
46  Copyright (c) 2009-11, President and Fellows of Harvard College.
47  All rights reserved.
48 
49  Redistribution and use in source and binary forms, with or without
50  modification, are permitted provided that the following conditions are met:
51 
52  Redistributions of source code must retain the above copyright notice,
53  this list of conditions and the following disclaimer.
54  Redistributions in binary form must reproduce the above copyright notice,
55  this list of conditions and the following disclaimer in the documentation
56 // and/or other materials provided with the distribution.
57  Neither the name of the President and Fellows of Harvard College
58  nor the names of its contributors may be used to endorse or promote
59  products derived from this software without specific prior written
60  permission.
61 
62  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
63  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
64  THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
65  PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
66  BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
67  OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
68  OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
69  OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
70  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
71  OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
72  ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
73 
74  =========================================================================*/
75 
77 
78 #include "hoverpoints.h"
79 
80 //vtk
81 #include "vtkLookupTable.h"
82 
83 //-------------------------------------------------------------------------
84 
86  double iMax,
87  QWidget *parent)
88  : QWidget(parent), m_color(iColor)
89 {
90 
91  // set max value
92  m_Max = iMax;
93 
94  // set minimum size to avoid bad appearance
95  this->setMinimumWidth(50);
96  this->setMinimumHeight(50);
97 
98  setAttribute(Qt::WA_NoBackground);
99 
100  // LUT curve
103  // connect signal
104  connect(this, SIGNAL(enableLUTCurve(bool)), m_LUTPoints, SLOT(setEnabled(bool)));
105 
106  // opacity TF
109  // connect signal
110  connect(this, SIGNAL(enableOpacityTF(bool)), m_OpacityTFPoints, SLOT(setEnabled(bool)));
111  connect(m_OpacityTFPoints, SIGNAL(pointsChanged(QPolygonF)), this, SIGNAL(opacityChanged()));
112 
113  // set size policy
114  setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
115 }
116 //-------------------------------------------------------------------------
117 
118 //-------------------------------------------------------------------------
120 {
121  return m_OpacityTFPoints->points();
122 }
123 //-------------------------------------------------------------------------
124 
125 //-------------------------------------------------------------------------
127 {
128  // generate shade, if necessary
129  if (m_shade.isNull() || m_shade.size() != size())
130  {
131  generateShade();
132  }
133 
134  // draw shade
135  QPainter p(this);
136  p.drawImage(0, 0, m_shade);
137  p.setPen(QColor(146, 146, 146));
138  p.drawRect(0, 0, width() - 1, height() - 1);
139 
140  // draw histogram
141  if(m_Histogram.size() > 0)
142  {
143  QVector<QPointF> listOfPoints;
144  qreal x_range = m_Histogram.size();
145 
146  for(int i=0; i<x_range; ++i)
147  {
148  QPointF point(i*(width()-1)/x_range, (height()-1) - m_Histogram[i]*(height()-1));
149  QPointF point2(i*(width()-1)/x_range, (height()-1));
150  listOfPoints.push_back(point2);
151  listOfPoints.push_back(point);
152  }
153  p.drawLines(listOfPoints);
154  }
155 }
156 //-------------------------------------------------------------------------
157 
158 //-------------------------------------------------------------------------
160 {
161  m_shade = QImage(size(), QImage::Format_RGB32);
162  QLinearGradient shade(0, 0, 0, height());
163  shade.setColorAt(1, Qt::black);
164 
165  shade.setColorAt(0, m_color);
166 
167  QPainter p(&m_shade);
168  p.fillRect(rect(), shade);
169 }
170 //-------------------------------------------------------------------------
171 
172 //-------------------------------------------------------------------------
173 void
176 {
177  m_OpacityTFPoints->setPoints(iPoints);
181 }
182 //-------------------------------------------------------------------------
183 
184 //-------------------------------------------------------------------------
185 void
187 AddPointsToLUT(const QPolygonF& iPoints)
188 {
189  m_LUTPoints->setPoints(iPoints);
190 }
191 //-------------------------------------------------------------------------
192 
193 //-------------------------------------------------------------------------
194 void
196 UpdateLookupTable(vtkLookupTable* iLUT, qreal iGamma, qreal iMin, qreal iMax)
197 {
198  QPolygonF iPoints;
199  int numTableValues = m_Max;
200  qreal width = this->width();
201  qreal height = this->height();
202  iLUT->SetNumberOfTableValues(iMax-iMin);
203 
204  // points affected with gamma correction, in the window
205  int count = 0;
206 
207  // first point
208  iPoints << QPointF((qreal)(iMin)*(width-1)/numTableValues, height - 1);
209  iLUT->SetTableValue(count, 0, 0, 0);
210  count++;
211 
212  for(int i=iMin+1; i<iMax-1; ++i)
213  {
214  qreal input = ((qreal)i - iMin)/((iMax-iMin));
215  qreal power = (qreal)(pow(input, iGamma));
216  qreal temp_height = (height-1)*(1-power);
217 
218  iPoints << QPointF((qreal)(i)*(width-1)/numTableValues,temp_height);
219 
220  iLUT->SetTableValue(count,
221  power*m_color.redF(),
222  power*m_color.greenF(),
223  power*m_color.blueF());
224  count++;
225  }
226 
227  // last point
228  iPoints << QPointF((qreal)(iMax)*(width-1)/numTableValues,0);
229  iLUT->SetTableValue(count, m_color.redF(), m_color.greenF(), m_color.blueF());
230 
231  iLUT->SetRange(iMin, iMax);
232 
233  iLUT->Modified();
234 
235  // print new curve
236  m_LUTPoints->setPoints(iPoints);
237  update();
238 }
239 //-------------------------------------------------------------------------
240 
241 //-------------------------------------------------------------------------
242 void
245 {
246  m_Histogram = iHistogram;
247 }
248 //-------------------------------------------------------------------------
249 
250 //-------------------------------------------------------------------------
251 void
254 {
255  // reset opacity TF
257  points << QPointF(0, height())
258  << QPointF(width(),0);
259  m_OpacityTFPoints->setPoints(points);
263 }
264 //-------------------------------------------------------------------------
265 
266 //-------------------------------------------------------------------------
267 void
270 {
271  // modify color
272  m_color = iColor;
273  // generate new shade
274  generateShade();
275  // update the shade
276  update();
277 }
278 //-------------------------------------------------------------------------
279 
280 //-------------------------------------------------------------------------
281 void
283 setMax(double iMax)
284 {
285  m_Max = iMax;
286 }
287 //-------------------------------------------------------------------------
QVector< qreal > m_Histogram
the histogram
void fillRect(const QRectF &rectangle, const QBrush &brush)
QPolygonF points() const
Definition: hoverpoints.h:120
qreal redF() const
void setColorAt(qreal position, const QColor &color)
void setPointLock(int pos, LockType lock)
Definition: hoverpoints.h:136
qreal blueF() const
void setMinimumWidth(int minw)
void setSortType(SortType sortType)
Definition: hoverpoints.h:127
void drawLines(const QLineF *lines, int lineCount)
void setAttribute(Qt::WidgetAttribute attribute, bool on)
bool isNull() const
void update()
void enableLUTCurve(bool)
enable/disable LUT curve
int width() const
void paintEvent(QPaintEvent *e)
Paint event: 1- generate new shade is size of the widget changed 2- draw the shade 3- draw the histog...
QSize size() const
void drawRect(const QRectF &rectangle)
GoTransferFunctionWidget(QColor iColor, double iMax, QWidget *parent)
void setEnabled(bool)
void AddPointsToOpacityTF(const QPolygonF &iPoints)
Add points to the opacity transfer function. Called at initialization or reset.
void opacityChanged()
Point added in the Opacity TF then update the visualization.
void setPen(const QColor &color)
HoverPoints * m_LUTPoints
LUT points.
void AddPointsToLUT(const QPolygonF &iPoints)
Add points to the LUT. Called at initialization or reset.
double m_Max
Maximum pixel value in the current channel at given time point.
qreal greenF() const
void setSizePolicy(QSizePolicy)
QRect rect() const
void UpdateLookupTable(vtkLookupTable *iLUT, qreal iGamma, qreal iMin, qreal iMax)
Modify LUT with given parameters.
HoverPoints * m_OpacityTFPoints
Opacity transfer function points.
void setMax(double iMax)
Set maximum pixel intensity for current channel at current T point.
void drawImage(const QRectF &target, const QImage &image, const QRectF &source, QFlags< Qt::ImageConversionFlag > flags)
QImage m_shade
Shade generated, based on the color.
void setPoints(const QPolygonF &points)
QColor m_color
Color of the current channel.
void setMinimumHeight(int minh)
QSize size() const
void push_back(const T &value)
void setConnectionType(ConnectionType connectionType)
Definition: hoverpoints.h:130
void setColor(QColor iColor)
Set the color of the channel. 1- Modify the color 2- Update the shade 3- Update the visualization...
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
int size() const
void generateShade()
Generate the shade when the color changed.
void SetHistogram(QVector< qreal > iHistogram)
Set the histogram.
void ResetOpacity()
Reset the opacity TF from min to max, from 0 to 1.
int height() const
void enableOpacityTF(bool)
enable/disable opacity TF