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
e95c73fe
Commit
e95c73fe
authored
Mar 21, 2011
by
Sebastian Eichelbaum
Browse files
[CHANGE] - improved colormap a bit.
parent
c32fd995
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
170 additions
and
27 deletions
+170
-27
src/kernel/modules/data/WMData.cpp
src/kernel/modules/data/WMData.cpp
+2
-2
src/modules/colormapper/WMColormapper.cpp
src/modules/colormapper/WMColormapper.cpp
+126
-25
src/modules/colormapper/WMColormapper.h
src/modules/colormapper/WMColormapper.h
+42
-0
No files found.
src/kernel/modules/data/WMData.cpp
View file @
e95c73fe
...
...
@@ -397,7 +397,7 @@ void WMData::moduleMain()
// textures also provide properties
if
(
m_dataSet
->
isTexture
()
)
{
WGEColormapping
::
registerTexture
(
m_dataSet
->
getTexture2
(),
m_
data
Name
->
get
()
);
WGEColormapping
::
registerTexture
(
m_dataSet
->
getTexture2
(),
m_
runtime
Name
->
get
()
);
m_properties
->
addProperty
(
m_dataSet
->
getTexture2
()
->
getProperties
()
);
m_infoProperties
->
addProperty
(
m_dataSet
->
getTexture2
()
->
getInformationProperties
()
);
}
...
...
@@ -471,7 +471,7 @@ void WMData::moduleMain()
// textures also provide properties
// if ( m_dataSet->isTexture() )
{
WGEColormapping
::
registerTexture
(
m_dataSet
->
getTexture2
(),
m_
data
Name
->
get
()
);
WGEColormapping
::
registerTexture
(
m_dataSet
->
getTexture2
(),
m_
runtime
Name
->
get
()
);
m_properties
->
addProperty
(
m_dataSet
->
getTexture2
()
->
getProperties
()
);
m_infoProperties
->
addProperty
(
m_dataSet
->
getTexture2
()
->
getInformationProperties
()
);
}
...
...
src/modules/colormapper/WMColormapper.cpp
View file @
e95c73fe
...
...
@@ -91,11 +91,64 @@ void WMColormapper::properties()
m_replace
=
m_properties
->
addProperty
(
"Keep position"
,
"If true, new texture on the input connector get placed in the list where the old one was."
,
true
);
m_showColorbar
=
m_properties
->
addProperty
(
"Show Colorbar"
,
"If true, a colorbar is shown for the current colormap."
,
false
);
WPropGroup
colorBarGroup
=
m_properties
->
addPropertyGroup
(
"Colorbar"
,
"The colorbar with several properties."
);
m_showColorbar
=
colorBarGroup
->
addProperty
(
"Show Colorbar"
,
"If true, a colorbar is shown for the current colormap."
,
false
);
m_colorBarBorder
=
colorBarGroup
->
addProperty
(
"Show Border"
,
"If true, a thin white border is shown around the colorbar."
,
true
);
m_colorBarName
=
colorBarGroup
->
addProperty
(
"Show Name"
,
"If true, a shortened version of the data name is shown."
,
true
);
m_colorBarLabels
=
colorBarGroup
->
addProperty
(
"Colorbar Labels"
,
"This defines the number of labels."
,
10
);
m_colorBarLabels
->
setMin
(
0
);
m_colorBarLabels
->
setMax
(
55
);
WModule
::
properties
();
}
/**
* Formats a given string to have the specified maximum length.
*
* \param str the string
* \param maxLen max length
*
* \return formatted string
*/
std
::
string
format
(
std
::
string
str
,
size_t
maxLen
=
45
)
{
// string will be at least 9 chars long: because of " [...] " + first and last char.
WAssert
(
maxLen
>=
9
,
"MaxLen has to be 9 or more."
);
std
::
ostringstream
ss
;
// cut away some stuff
if
(
str
.
length
()
>
maxLen
)
{
size_t
keep
=
maxLen
-
3
;
// how much chars to keep?
size_t
keepFront
=
keep
/
2
;
size_t
keepEnd
=
keep
-
keepFront
;
ss
<<
str
.
substr
(
0
,
keepFront
)
<<
" [...] "
<<
str
.
substr
(
str
.
length
()
-
keepEnd
,
keepEnd
);
}
else
{
ss
<<
str
;
}
return
ss
.
str
();
}
/**
* Formats a number properly to be usable as label
*
* \tparam T the type of value.
* \param number the number to format
*
* \return the formated number
*/
template
<
typename
T
>
std
::
string
format
(
T
number
)
{
std
::
ostringstream
ss
;
ss
.
precision
(
3
);
ss
<<
number
;
return
ss
.
str
();
}
void
WMColormapper
::
moduleMain
()
{
// let the main loop awake if the data changes or the properties changed.
...
...
@@ -139,8 +192,9 @@ void WMColormapper::moduleMain()
// create camera oriented 2d projection
m_barProjection
=
new
osg
::
Projection
();
m_barProjection
->
addUpdateCallback
(
new
WGENodeMaskCallback
(
m_showColorbar
)
);
m_barProjection
->
addUpdateCallback
(
new
WGENodeMaskCallback
(
m_active
)
);
m_barProjection
->
setMatrix
(
osg
::
Matrix
::
ortho2D
(
0
,
1.0
,
0
,
1.0
)
);
m_barProjection
->
getOrCreateStateSet
()
->
setRenderBinDetails
(
1
1
,
"RenderBin"
);
m_barProjection
->
getOrCreateStateSet
()
->
setRenderBinDetails
(
1
5
,
"RenderBin"
);
m_barProjection
->
getOrCreateStateSet
()
->
setDataVariance
(
osg
::
Object
::
DYNAMIC
);
m_barProjection
->
getOrCreateStateSet
()
->
setMode
(
GL_DEPTH_TEST
,
osg
::
StateAttribute
::
OFF
);
m_barProjection
->
getOrCreateStateSet
()
->
setMode
(
GL_LIGHTING
,
osg
::
StateAttribute
::
OFF
);
...
...
@@ -149,32 +203,18 @@ void WMColormapper::moduleMain()
// create a colorbar geode
m_colorBar
=
wge
::
genFinitePlane
(
osg
::
Vec3
(
0.025
,
0.1
,
0.0
),
osg
::
Vec3
(
0.025
,
0.0
,
0.0
),
osg
::
Vec3
(
0.0
,
0.8
,
0.0
)
);
osg
::
ref_ptr
<
osg
::
Geode
>
colorBarBorder
=
wge
::
genFinitePlane
(
osg
::
Vec3
(
0.025
-
borderWidth
,
0.1
-
borderWidth
,
0.
0
),
osg
::
Vec3
(
0.025
+
2.0
*
borderWidth
,
0.0
,
0.
0
),
osg
::
Vec3
(
0.0
,
0.8
+
2.0
*
borderWidth
,
0.
0
)
);
osg
::
ref_ptr
<
osg
::
Geode
>
colorBarBorder
=
wge
::
genFinitePlane
(
osg
::
Vec3
(
0.025
-
borderWidth
,
0.1
-
borderWidth
,
-
0.
1
),
osg
::
Vec3
(
0.025
+
2.0
*
borderWidth
,
0.0
,
-
0.
1
),
osg
::
Vec3
(
0.0
,
0.8
+
2.0
*
borderWidth
,
-
0.
1
)
);
m_colorBar
->
getOrCreateStateSet
()
->
addUniform
(
new
WGEPropertyUniform
<
WPropSelection
>
(
"u_colormap"
,
dataSet
->
getTexture2
()
->
colormap
()
)
);
colormapShader
->
apply
(
m_colorBar
);
// add the label scale
osg
::
ref_ptr
<
WGELabel
>
topLabel
=
new
WGELabel
();
topLabel
->
setCharacterSize
(
2
);
topLabel
->
setPosition
(
osg
::
Vec3
(
0.055
,
0.9
,
0.0
)
);
topLabel
->
setText
(
boost
::
lexical_cast
<
std
::
string
>
(
dataSet
->
getTexture2
()
->
minimum
()
->
get
()
+
dataSet
->
getTexture2
()
->
scale
()
->
get
()
)
);
topLabel
->
setCharacterSize
(
0.02
);
topLabel
->
setAlignment
(
osgText
::
Text
::
LEFT_TOP
);
osg
::
ref_ptr
<
WGELabel
>
bottomLabel
=
new
WGELabel
();
bottomLabel
->
setPosition
(
osg
::
Vec3
(
0.055
,
0.1
,
0.0
)
);
bottomLabel
->
setText
(
boost
::
lexical_cast
<
std
::
string
>
(
dataSet
->
getTexture2
()
->
minimum
()
->
get
()
)
);
bottomLabel
->
setCharacterSize
(
0.02
);
// add the name label
osg
::
ref_ptr
<
WGELabel
>
nameLabel
=
new
WGELabel
();
nameLabel
->
setPosition
(
osg
::
Vec3
(
0.015
,
0.9
,
0.0
)
);
nameLabel
->
setText
(
dataSet
->
getTexture2
()
->
name
()
->
get
()
);
nameLabel
->
setCharacterSize
(
0.0
2
);
nameLabel
->
setText
(
format
(
dataSet
->
getTexture2
()
->
name
()
->
get
()
)
);
nameLabel
->
setCharacterSize
(
0.0
15
);
nameLabel
->
setLayout
(
osgText
::
TextBase
::
VERTICAL
);
nameLabel
->
setAlignment
(
osgText
::
Text
::
BASE_LINE
);
nameLabel
->
setUpdateCallback
(
new
WGEFunctorCallback
<
osg
::
Drawable
>
(
...
...
@@ -188,16 +228,26 @@ void WMColormapper::moduleMain()
// this geode contains the labels
osg
::
ref_ptr
<
osg
::
Geode
>
labels
=
new
osg
::
Geode
();
labels
->
addDrawable
(
topLabel
);
labels
->
addDrawable
(
bottomLabel
);
labels
->
addDrawable
(
nameLabel
);
m_scaleLabels
=
new
osg
::
Geode
();
m_scaleLabels
->
addUpdateCallback
(
new
WGEFunctorCallback
<
osg
::
Node
>
(
boost
::
bind
(
&
WMColormapper
::
updateColorbarScale
,
this
,
_1
)
)
);
// set some callbacks
colorBarBorder
->
addUpdateCallback
(
new
WGENodeMaskCallback
(
m_colorBarBorder
)
);
labels
->
addUpdateCallback
(
new
WGENodeMaskCallback
(
m_colorBarName
)
);
// build pipeline
matrix
->
addChild
(
colorBarBorder
);
matrix
->
addChild
(
m_colorBar
);
matrix
->
addChild
(
m_scaleLabels
);
matrix
->
addChild
(
labels
);
m_barProjection
->
addChild
(
matrix
);
m_valueMin
=
dataSet
->
getTexture2
()
->
minimum
()
->
get
();
m_valueScale
=
dataSet
->
getTexture2
()
->
scale
()
->
get
();
// add
WKernel
::
getRunningKernel
()
->
getGraphicsEngine
()
->
getScene
()
->
insert
(
m_barProjection
);
}
...
...
@@ -269,7 +319,58 @@ void WMColormapper::updateColorbarName( osg::Drawable* label )
{
if
(
m_lastDataSet
)
{
dynamic_cast
<
WGELabel
*
>
(
label
)
->
setText
(
m_lastDataSet
->
getTexture2
()
->
name
()
->
get
()
);
dynamic_cast
<
WGELabel
*
>
(
label
)
->
setText
(
format
(
m_lastDataSet
->
getTexture2
()
->
name
()
->
get
()
)
);
}
}
void
WMColormapper
::
updateColorbarScale
(
osg
::
Node
*
scaleLabels
)
{
if
(
m_colorBarLabels
->
changed
(
true
)
)
{
const
double
labelXPos
=
0.060
;
osg
::
Geode
*
g
=
scaleLabels
->
asGeode
();
g
->
removeDrawables
(
0
,
g
->
getNumDrawables
()
);
size_t
num
=
m_colorBarLabels
->
get
(
true
);
double
coordStep
=
0.8
/
static_cast
<
double
>
(
num
-
1
);
double
valueStep
=
m_valueScale
/
static_cast
<
double
>
(
num
-
1
);
// less than 2 labels is useless
if
(
num
<
2
)
{
return
;
}
osg
::
Vec3Array
*
lineVerts
=
new
osg
::
Vec3Array
();
// create enough labels.
for
(
size_t
i
=
0
;
i
<
num
;
++
i
)
{
double
value
=
m_valueMin
+
(
valueStep
*
i
);
// create the label
osg
::
ref_ptr
<
WGELabel
>
label
=
new
WGELabel
();
label
->
setPosition
(
osg
::
Vec3
(
labelXPos
,
0.1
+
i
*
coordStep
,
0.0
)
);
// bar goes from 0.1 to 0.9 in our coordinate system
label
->
setText
(
format
(
value
)
);
label
->
setCharacterSize
(
0.015
);
label
->
setAlignment
(
osgText
::
Text
::
LEFT_CENTER
);
g
->
addDrawable
(
label
);
// create the line next to the label
lineVerts
->
push_back
(
osg
::
Vec3
(
labelXPos
-
0.010
,
0.1
+
i
*
coordStep
,
0.0
)
);
lineVerts
->
push_back
(
osg
::
Vec3
(
labelXPos
-
0.005
,
0.1
+
i
*
coordStep
,
0.0
)
);
}
// create the line drawable
osg
::
Geometry
*
lines
=
new
osg
::
Geometry
();
lines
->
setVertexArray
(
lineVerts
);
osg
::
Vec3Array
*
color
=
new
osg
::
Vec3Array
();
color
->
push_back
(
osg
::
Vec3
(
1.0
,
1.0
,
1.0
)
);
lines
->
setColorArray
(
color
);
lines
->
setColorBinding
(
osg
::
Geometry
::
BIND_OVERALL
);
lines
->
addPrimitiveSet
(
new
osg
::
DrawArrays
(
GL_LINES
,
0
,
lineVerts
->
size
()
)
);
g
->
addDrawable
(
lines
);
}
}
src/modules/colormapper/WMColormapper.h
View file @
e95c73fe
...
...
@@ -114,6 +114,21 @@ private:
*/
boost
::
shared_ptr
<
WDataSetSingle
>
m_lastDataSet
;
/**
* The min of the current dataset. We store them here to avoid many calls to getTexture()->minimum()->get() and scale()->get().
*/
double
m_valueMin
;
/**
* The max of the current dataset. We store them here to avoid many calls to getTexture()->minimum()->get() and scale()->get().
*/
double
m_valueMax
;
/**
* The scaling factor of the current dataset. We store them here to avoid many calls to getTexture()->minimum()->get() and scale()->get().
*/
double
m_valueScale
;
/**
* If true, the new texture gets placed at the position of the old one in the texture sorter
*/
...
...
@@ -124,6 +139,21 @@ private:
*/
WPropBool
m_showColorbar
;
/**
* The number of colorbar labels
*/
WPropInt
m_colorBarLabels
;
/**
* Show colorbar name?
*/
WPropBool
m_colorBarName
;
/**
* Show the border?
*/
WPropBool
m_colorBarBorder
;
/**
* The projection node for the colorbar and labels
*/
...
...
@@ -140,6 +170,18 @@ private:
* \param label the label to update
*/
void
updateColorbarName
(
osg
::
Drawable
*
label
);
/**
* The colorbar scale labels
*/
osg
::
ref_ptr
<
osg
::
Geode
>
m_scaleLabels
;
/**
* Callback which adds/removes scale labels to the colorbar.
*
* \param scaleLabels the geode containing the labels.
*/
void
updateColorbarScale
(
osg
::
Node
*
scaleLabels
);
};
#endif // WMCOLORMAPPER_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