Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
OpenWalnut
OpenWalnut Core
Commits
31121062
Commit
31121062
authored
Nov 30, 2011
by
Mario Hlawitschka
Browse files
[STYLE] mainly style changes and some documentation.
parent
2e530ae4
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
196 additions
and
192 deletions
+196
-192
src/core/common/WColor.cpp
src/core/common/WColor.cpp
+1
-1
src/qt4gui/qt4/controlPanel/WPropertyTransferFunctionWidget.h
...qt4gui/qt4/controlPanel/WPropertyTransferFunctionWidget.h
+2
-2
src/qt4gui/qt4/controlPanel/transferFunction/WTransferFunctionWidget.cpp
...controlPanel/transferFunction/WTransferFunctionWidget.cpp
+38
-46
src/qt4gui/qt4/controlPanel/transferFunction/WTransferFunctionWidget.h
...4/controlPanel/transferFunction/WTransferFunctionWidget.h
+155
-143
No files found.
src/core/common/WColor.cpp
View file @
31121062
...
...
@@ -32,7 +32,7 @@
#include "../common/WStringUtils.h"
#include "WColor.h"
// initialize static palette
// initialize static palette
namespace
defaultColor
{
/** the default palette colors */
...
...
src/qt4gui/qt4/controlPanel/WPropertyTransferFunctionWidget.h
View file @
31121062
...
...
@@ -111,8 +111,8 @@ protected:
*/
QHBoxLayout
m_infoLayout
;
WTransferFunctionWidget
m_transferFunction
;
WTransferFunction
lastTransferFunction
;
WTransferFunctionWidget
m_transferFunction
;
//< the current transfer function
WTransferFunction
lastTransferFunction
;
//< the previous transfer function used for comparison when updated
/**
* internal synchronization flag
...
...
src/qt4gui/qt4/controlPanel/transferFunction/WTransferFunctionWidget.cpp
View file @
31121062
...
...
@@ -29,7 +29,6 @@
#include "QtGui/QPaintEngine"
#include "QtGui/QGraphicsSceneMouseEvent"
#include "core/common/WTransferFunction.h"
#include "WTransferFunctionPoint.h"
...
...
@@ -136,7 +135,7 @@ namespace
}
}
void
WTransferFunctionWidget
::
sample1D
W
TransferFunction
(
unsigned
char
*
array
,
int
width
)
void
WTransferFunctionWidget
::
sample1DTransferFunction
(
unsigned
char
*
array
,
int
width
)
{
if
(
!
first
||
!
cfirst
)
return
;
...
...
@@ -184,7 +183,7 @@ void WTransferFunctionWidget::sample1DWTransferFunction( unsigned char*array, in
//! inaternal representation needs ARGB, but we do not display alpha component, so set it to 255
void
WTransferFunctionWidget
::
sample1D
W
TransferFunctionForDisplay
(
unsigned
char
*
array
,
int
width
)
void
WTransferFunctionWidget
::
sample1DTransferFunctionForDisplay
(
unsigned
char
*
array
,
int
width
)
{
double
scenewidth
=
scene
->
width
();
//WTransferFunctionPoint *acurrent( first );
...
...
@@ -207,18 +206,10 @@ void WTransferFunctionWidget::sample1DWTransferFunctionForDisplay( unsigned char
QColor
rgb
=
blend
(
ccurrent
->
getRight
()
->
getColor
(),
ct
,
ccurrent
->
getColor
(),
(
1.
-
ct
)
);
// FIXME: this encoding differs from platform to platform. Even though I asked for ARGB, it is RGBA on Linux
#ifdef Q_WS_MAC
array
[
i
*
4
+
0
]
=
255
;
//alpha;
array
[
i
*
4
+
1
]
=
rgb
.
red
();
array
[
i
*
4
+
2
]
=
rgb
.
green
();
array
[
i
*
4
+
3
]
=
rgb
.
blue
();
#else
array
[
i
*
4
+
2
]
=
rgb
.
red
();
array
[
i
*
4
+
1
]
=
rgb
.
green
();
array
[
i
*
4
+
0
]
=
rgb
.
blue
();
array
[
i
*
4
+
3
]
=
255
;
//alpha;
#endif
array
[
i
*
4
+
3
]
=
255
;
//alpha; //< displaying alpha in the gui does not make sense for me
}
}
}
...
...
@@ -227,16 +218,12 @@ void WTransferFunctionWidget::sample1DWTransferFunctionForDisplay( unsigned char
WTransferFunctionWidget
::~
WTransferFunctionWidget
()
{
// debug loop
// std::cout << "~WTransferFunctionWidget()" << std::endl;
WTransferFunctionPoint
*
current
(
first
);
while
(
current
)
{
// std::cout << "item: " << current->pos().x() << ", " << current->pos().y() << std::endl;
current
=
current
->
getRight
();
}
// std::cout << "done." << std::endl;
// // loop for debuging only
// WTransferFunctionPoint *current( first );
// while ( current )
// {
// current = current->getRight();
// }
// hopefully, the QScene will delete all its items.
}
...
...
@@ -247,7 +234,7 @@ void WTransferFunctionWidget::setMyBackground()
if
(
background
)
{
sample1D
W
TransferFunctionForDisplay
(
texturearray
,
transferFunctionSize
);
sample1DTransferFunctionForDisplay
(
texturearray
,
transferFunctionSize
);
QImage
image
(
texturearray
,
transferFunctionSize
,
1
,
QImage
::
Format_ARGB32
);
QPixmap
pixmap
(
transferFunctionSize
,
1
);
...
...
@@ -275,17 +262,17 @@ void WTransferFunctionWidget::drawBackground( QPainter *painter, const QRectF &r
void
WTransferFunctionWidget
::
setHistogram
(
const
std
::
vector
<
double
>
&
newHistogram
)
{
// std::cout << "Histogram updated." << std::endl;
histogram
->
data
=
newHistogram
;
// std::cout << "Histogram size" << histogram->data.size() << std::endl;
histogram
->
update
();
forceRedraw
();
}
void
WTransferFunctionWidget
::
dataChanged
()
{
if
(
!
initialized
)
return
;
// std::cout << "dataChanged()" << std::endl;
if
(
!
initialized
)
{
return
;
}
this
->
updateTransferFunction
();
this
->
setMyBackground
();
forceRedraw
();
...
...
@@ -293,7 +280,10 @@ void WTransferFunctionWidget::dataChanged()
void
WTransferFunctionWidget
::
forceRedraw
()
{
if
(
!
initialized
)
return
;
if
(
!
initialized
)
{
return
;
}
QRectF
viewport
(
scene
->
sceneRect
()
);
scene
->
invalidate
(
viewport
);
this
->
update
();
...
...
@@ -441,7 +431,6 @@ void WTransferFunctionWidget::insertPoint( const QPointF& position )
scene
->
addItem
(
point
);
scene
->
addItem
(
line
);
// insert into list
WTransferFunctionPoint
*
left
(
this
->
findPointOnLeft
(
position
)
);
if
(
left
)
...
...
@@ -577,26 +566,29 @@ namespace
void
WTransferFunctionWidget
::
updateTransferFunction
()
{
WTransferFunction
tf
;
std
::
vector
<
double
>
hist
(
histogram
->
data
);
//< copy data, this will be deleted
tf
.
setHistogram
(
hist
);
// get the data back because we need this for comparison
{
// this part does not trigger qt rendering updates
std
::
vector
<
double
>
hist
(
histogram
->
data
);
//< copy data, this will be deleted
tf
.
setHistogram
(
hist
);
// get the data back because we need this for comparison
QRectF
bb
=
scene
->
sceneRect
();
QRectF
bb
=
scene
->
sceneRect
();
WTransferFunctionColorPoint
*
cp
(
cfirst
);
while
(
cp
)
{
double
iso
=
(
cp
->
pos
().
x
()
-
bb
.
x
()
)
/
bb
.
width
();
tf
.
addColor
(
iso
,
toWColor
(
cp
->
getColor
()
)
);
cp
=
cp
->
getRight
();
}
WTransferFunctionColorPoint
*
cp
(
cfirst
);
while
(
cp
)
{
double
iso
=
(
cp
->
pos
().
x
()
-
bb
.
x
()
)
/
bb
.
width
();
tf
.
addColor
(
iso
,
toWColor
(
cp
->
getColor
()
)
);
cp
=
cp
->
getRight
();
}
WTransferFunctionPoint
*
p
(
first
);
while
(
p
)
{
double
iso
=
(
p
->
pos
().
x
()
-
bb
.
x
()
)
/
bb
.
width
();
double
alpha
=
1.
-
(
(
p
->
pos
().
y
()
-
bb
.
y
()
)
/
bb
.
height
()
);
tf
.
addAlpha
(
iso
,
alpha
);
p
=
p
->
getRight
();
WTransferFunctionPoint
*
p
(
first
);
while
(
p
)
{
double
iso
=
(
p
->
pos
().
x
()
-
bb
.
x
()
)
/
bb
.
width
();
double
alpha
=
1.
-
(
(
p
->
pos
().
y
()
-
bb
.
y
()
)
/
bb
.
height
()
);
tf
.
addAlpha
(
iso
,
alpha
);
p
=
p
->
getRight
();
}
}
// std::cout << "updating gui" << parent << std::endl;
...
...
src/qt4gui/qt4/controlPanel/transferFunction/WTransferFunctionWidget.h
View file @
31121062
...
...
@@ -66,149 +66,161 @@ class WTransferFunctionWidget :public QGraphicsView
{
Q_OBJECT
public:
typedef
QGraphicsView
BaseClass
;
WTransferFunctionWidget
(
QWidget
*
qparent
=
0x0
,
WTransferFunctionGuiNotificationClass
*
parent
=
0x0
);
virtual
~
WTransferFunctionWidget
();
/**
* called to notify the widget of achange of data
*/
//void externalDataChange( const WTransferFunction &tf );
/**
* called from external to set histogram
*/
void
setHistogram
(
const
std
::
vector
<
double
>
&
histogram
);
/**
* Redraw the widget
*/
void
forceRedraw
();
void
setTransferFunction
();
// FIXME
/** set the current active point => this should be changed to QGraphicsScene
* object selection */
void
setCurrent
(
WTransferFunctionPoint
*
current
)
{
this
->
current
=
current
;
this
->
ccurrent
=
0x0
;
}
/** similart to setCurrent but for Color control points */
void
setCurrentColor
(
WTransferFunctionColorPoint
*
ccurrent
)
{
this
->
ccurrent
=
ccurrent
;
this
->
current
=
0x0
;
}
/** sample the transfer function into a 1D RGBA texture */
void
sample1DWTransferFunction
(
unsigned
char
*
array
,
int
width
);
/** sample the transfer function into a 1D RGBA, ABGR, ARGB, ... whatever...
This function should work on the graphics native system, but I did not find the
function to get information about the alignment, yet.
(X11 Linux, little endian: ABRG. OSX: ARGB, X11 on OSX from Linux host->???)
*/
void
sample1DWTransferFunctionForDisplay
(
unsigned
char
*
array
,
int
width
);
//void dropEvent( QGraphicsSceneDragDropEvent* event );
//void dragEnterEvent( QGraphicsSceneDragDropEvent* event );
/**
* Insert a new alpha control point at scene position position.
*/
void
insertPoint
(
const
QPointF
&
position
);
/**
* same as insertPoint but in normalized coordinates and not in screen space
*/
void
insertPointNormalized
(
const
QPointF
&
position
);
/**
* Insert a new color control point at scene position pos (only the x-value is relevant)
* If a color is provided, it is used. Otherwise, a new color is used interpolating the
* current color map.
*/
void
insertColor
(
const
QPointF
&
pos
,
QColor
const
*
const
color
=
0
);
/**
* Same as insertColor but in normalized coordinates, i.e., [ 0...1 ] along x
*/
void
insertColorNormalized
(
const
QPointF
&
pos
,
QColor
const
*
const
color
=
0
);
/**
* Remove all points from the transfer function widget to be able to insert new points
*/
void
clearTransferFunction
();
public
slots
:
/**
* Notification that the data changed, i.e., a control point has been moved or a color changed
* */
void
dataChanged
();
protected:
virtual
void
drawBackground
(
QPainter
*
painter
,
const
QRectF
&
rect
);
/**
* Interactions implemented so far:
* right click: insert new object (Ctrl+left click or two-finger tap on OSX)
* left click on objects: (handled by individual objects) move control points and select
* object
* double click on objects: (handled by individual objects) open parameter dialog, e.g.,
* to change the color
* "Delete" or "Backspace": delete selected itom
*/
virtual
void
keyPressEvent
(
QKeyEvent
*
event
);
/**
* for a documentation of the implemented actions confer the keyPressEvent documentation
*/
virtual
void
mousePressEvent
(
QMouseEvent
*
event
);
/**
* internal helper function: Find the point to the left of the given point
*/
WTransferFunctionPoint
*
findPointOnLeft
(
QPointF
position
);
/**
* internal helper function: Find the point to the left of the given color control point
*/
WTransferFunctionColorPoint
*
findCPointOnLeft
(
QPointF
position
);
void
updateTransferFunction
();
//void drawLineStrip( QPainter *painter );
/**
* internal helper function to update the QGraphicsPixmapItem that holds a representation
* of the current color map and displays it as a background of the widget.
* This function samples the texture into a QPixmap and updates the QGraphicsPixmapItem.
*/
void
setMyBackground
();
private:
WTransferFunctionGuiNotificationClass
*
parent
;
QGraphicsScene
*
scene
;
WTransferFunctionPoint
*
first
;
WTransferFunctionPoint
*
last
;
WTransferFunctionPoint
*
current
;
WTransferFunctionColorPoint
*
cfirst
;
WTransferFunctionColorPoint
*
clast
;
WTransferFunctionColorPoint
*
ccurrent
;
WTransferFunctionBackground
*
background
;
//< background that displays the color map
WTransferFunctionHistogram
*
histogram
;
//< item responsible for displaying histogram data
bool
initialized
;
public:
typedef
QGraphicsView
BaseClass
;
/**
* \param qparent parent widgeet
* \param parent a class that receives notifications
*/
WTransferFunctionWidget
(
QWidget
*
qparent
=
0x0
,
WTransferFunctionGuiNotificationClass
*
parent
=
0x0
);
virtual
~
WTransferFunctionWidget
();
/**
* called to notify the widget of achange of data
*/
//void externalDataChange( const WTransferFunction &tf );
/**
* called from external to set histogram
* \param histogram The histogram data
*/
void
setHistogram
(
const
std
::
vector
<
double
>
&
histogram
);
/**
* Redraw the widget
*/
void
forceRedraw
();
/** set the current active point => this should be changed to QGraphicsScene
* object selection */
void
setCurrent
(
WTransferFunctionPoint
*
current
)
{
this
->
current
=
current
;
this
->
ccurrent
=
0x0
;
}
/** similart to setCurrent but for Color control points */
void
setCurrentColor
(
WTransferFunctionColorPoint
*
ccurrent
)
{
this
->
ccurrent
=
ccurrent
;
this
->
current
=
0x0
;
}
/** sample the transfer function into a 1D RGBA texture */
void
sample1DTransferFunction
(
unsigned
char
*
array
,
int
width
);
/** sample the transfer function into a 1D RGBA, ABGR, ARGB, ... whatever...
This function should work on the graphics native system, but I did not find the
function to get information about the alignment, yet.
(X11 Linux, little endian: ABRG. OSX: ARGB, X11 on OSX from Linux host->???)
*/
void
sample1DTransferFunctionForDisplay
(
unsigned
char
*
array
,
int
width
);
//void dropEvent( QGraphicsSceneDragDropEvent* event );
//void dragEnterEvent( QGraphicsSceneDragDropEvent* event );
/**
* Insert a new alpha control point at scene position position.
* \param position the position of the point with position.x = iso and position.y = alpha in window coordinates.
*/
void
insertPoint
(
const
QPointF
&
position
);
/**
* same as insertPoint but in normalized coordinates and not in screen space
* \param position: same as in insertPoint, but scaled to [ 0..1 ]x[ 0..1 ]
*/
void
insertPointNormalized
(
const
QPointF
&
position
);
/**
* Insert a new color control point at scene position pos (only the x-value is relevant)
* If a color is provided, it is used. Otherwise, a new color is used interpolating the
* current color map.
* \param pos: the clicked position where pos.x = iso and pos.y is ignored
* \param color: the color of the new point. If color = 0, a new color is created by interpolating the neighbors.
*/
void
insertColor
(
const
QPointF
&
pos
,
QColor
const
*
const
color
=
0
);
/**
* Same as insertColor but in normalized coordinates, i.e., [ 0...1 ] along x
*/
void
insertColorNormalized
(
const
QPointF
&
pos
,
QColor
const
*
const
color
=
0
);
/**
* Remove all points from the transfer function widget to be able to insert new points
*/
void
clearTransferFunction
();
public
slots
:
/**
* Notification that the data changed, i.e., a control point has been moved or a color changed
* */
void
dataChanged
();
protected:
virtual
void
drawBackground
(
QPainter
*
painter
,
const
QRectF
&
rect
);
/**
* Interactions implemented so far:
* right click: insert new object (Ctrl+left click or two-finger tap on OSX)
* left click on objects: (handled by individual objects) move control points and select
* object
* double click on objects: (handled by individual objects) open parameter dialog, e.g.,
* to change the color
* "Delete" or "Backspace": delete selected itom
*/
virtual
void
keyPressEvent
(
QKeyEvent
*
event
);
/**
* for a documentation of the implemented actions confer the keyPressEvent documentation
*/
virtual
void
mousePressEvent
(
QMouseEvent
*
event
);
/**
* internal helper function: Find the point to the left of the given point
*/
WTransferFunctionPoint
*
findPointOnLeft
(
QPointF
position
);
/**
* internal helper function: Find the point to the left of the given color control point
*/
WTransferFunctionColorPoint
*
findCPointOnLeft
(
QPointF
position
);
void
updateTransferFunction
();
//void drawLineStrip( QPainter *painter );
/**
* internal helper function to update the QGraphicsPixmapItem that holds a representation
* of the current color map and displays it as a background of the widget.
* This function samples the texture into a QPixmap and updates the QGraphicsPixmapItem.
*/
void
setMyBackground
();
private:
/** the class that receives our update notifications */
WTransferFunctionGuiNotificationClass
*
parent
;
/** our scene */
QGraphicsScene
*
scene
;
/** linked list of alpha items */
WTransferFunctionPoint
*
first
;
//< first element
WTransferFunctionPoint
*
last
;
//< last element in list
WTransferFunctionPoint
*
current
;
//< currently selected/active element
/** linked list of color items */
WTransferFunctionColorPoint
*
cfirst
;
//< first element
WTransferFunctionColorPoint
*
clast
;
//< last element
WTransferFunctionColorPoint
*
ccurrent
;
//< currently selected/active color element
WTransferFunctionBackground
*
background
;
//< background that displays the color map
WTransferFunctionHistogram
*
histogram
;
//< item responsible for displaying histogram data
bool
initialized
;
//< set to true after initialization
};
#endif // WTRANSFERFUNCTIONWIDGET_H
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment