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
f14d9b6b
Commit
f14d9b6b
authored
Aug 04, 2010
by
schurade
Browse files
[ADD] fiber culling with a selection box tool
parent
099e89ce
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
154 additions
and
13 deletions
+154
-13
src/kernel/modules/fiberDisplay/WMFiberDisplay.cpp
src/kernel/modules/fiberDisplay/WMFiberDisplay.cpp
+78
-3
src/kernel/modules/fiberDisplay/WMFiberDisplay.h
src/kernel/modules/fiberDisplay/WMFiberDisplay.h
+37
-4
src/kernel/modules/fiberDisplay/shaders/WMFiberDisplay-Textured-fragment.glsl
...iberDisplay/shaders/WMFiberDisplay-Textured-fragment.glsl
+39
-6
No files found.
src/kernel/modules/fiberDisplay/WMFiberDisplay.cpp
View file @
f14d9b6b
...
...
@@ -93,6 +93,8 @@ void WMFiberDisplay::moduleMain()
m_moduleState
.
wait
();
// waits for firing of m_moduleState ( dataChanged, shutdown, etc. )
initCullBox
();
/////////////////////////////////////////////////////////////////////////////////////////
// what caused wait to return?
/////////////////////////////////////////////////////////////////////////////////////////
...
...
@@ -151,6 +153,32 @@ void WMFiberDisplay::update()
m_osgNode
->
setNodeMask
(
0xFFFFFFFF
);
}
}
if
(
!
m_showCullBox
->
get
()
)
{
m_cullBox
->
setNodeMask
(
0x0
);
}
else
{
m_cullBox
->
setNodeMask
(
0xFFFFFFFF
);
}
float
xMin
=
m_cullBox
->
getMinPos
()[
0
];
float
yMin
=
m_cullBox
->
getMinPos
()[
1
];
float
zMin
=
m_cullBox
->
getMinPos
()[
2
];
float
xMax
=
m_cullBox
->
getMaxPos
()[
0
];
float
yMax
=
m_cullBox
->
getMaxPos
()[
1
];
float
zMax
=
m_cullBox
->
getMaxPos
()[
2
];
m_uniformUseCullBox
->
set
(
m_activateCullBox
->
get
()
);
m_uniformInsideCullBox
->
set
(
m_insideCullBox
->
get
()
);
m_uniformCullBoxLBX
->
set
(
static_cast
<
float
>
(
xMin
)
);
m_uniformCullBoxLBY
->
set
(
static_cast
<
float
>
(
yMin
)
);
m_uniformCullBoxLBZ
->
set
(
static_cast
<
float
>
(
zMin
)
);
m_uniformCullBoxUBX
->
set
(
static_cast
<
float
>
(
xMax
)
);
m_uniformCullBoxUBY
->
set
(
static_cast
<
float
>
(
yMax
)
);
m_uniformCullBoxUBZ
->
set
(
static_cast
<
float
>
(
zMax
)
);
}
void
WMFiberDisplay
::
create
()
...
...
@@ -237,9 +265,14 @@ void WMFiberDisplay::properties()
"Updates the output connector with the currently selected fibers"
,
WPVBaseTypes
::
PV_TRIGGER_READY
,
boost
::
bind
(
&
WMFiberDisplay
::
updateOutput
,
this
)
);
m_cullBoxGroup
=
m_properties
->
addPropertyGroup
(
"Box Culling"
,
"Properties only related to the box culling."
);
m_activateCullBox
=
m_cullBoxGroup
->
addProperty
(
"Activate"
,
"activates the cull box"
,
false
);
m_showCullBox
=
m_cullBoxGroup
->
addProperty
(
"Show Cull Box"
,
"shows/hides the cull box"
,
false
);
m_insideCullBox
=
m_cullBoxGroup
->
addProperty
(
"Inside - Outside"
,
"show fibers inside or outside the cull box"
,
true
);
}
void
WMFiberDisplay
::
toggleTub
es
()
void
WMFiberDisplay
::
updateRenderMod
es
()
{
osg
::
StateSet
*
rootState
=
m_osgNode
->
getOrCreateStateSet
();
...
...
@@ -249,7 +282,7 @@ void WMFiberDisplay::toggleTubes()
updateTexture
();
}
if
(
m_useTubesProp
->
changed
()
||
m_useTextureProp
->
changed
()
)
if
(
m_useTubesProp
->
changed
()
||
m_useTextureProp
->
changed
()
||
m_activateCullBox
->
changed
()
)
{
if
(
m_useTubesProp
->
get
(
true
)
)
{
...
...
@@ -262,12 +295,13 @@ void WMFiberDisplay::toggleTubes()
rootState
->
addUniform
(
m_uniformTubeThickness
);
rootState
->
addUniform
(
osg
::
ref_ptr
<
osg
::
Uniform
>
(
new
osg
::
Uniform
(
"useTexture"
,
m_useTextureProp
->
get
()
)
)
);
}
else
if
(
m_useTextureProp
->
get
(
true
)
&&
!
m_useTubesProp
->
get
(
true
)
)
else
if
(
(
m_useTextureProp
->
get
(
true
)
&&
!
m_useTubesProp
->
get
(
true
)
)
||
m_activateCullBox
->
get
(
true
)
)
{
m_tubeDrawable
->
setUseTubes
(
false
);
updateTexture
();
m_shaderTubes
->
deactivate
(
m_osgNode
);
m_shaderTexturedFibers
->
apply
(
m_osgNode
);
m_uniformUseTexture
->
set
(
m_useTextureProp
->
get
()
);
}
else
{
...
...
@@ -376,6 +410,7 @@ void WMFiberDisplay::updateTexture()
void
WMFiberDisplay
::
initUniforms
(
osg
::
StateSet
*
rootState
)
{
m_uniformUseTexture
=
osg
::
ref_ptr
<
osg
::
Uniform
>
(
new
osg
::
Uniform
(
"useTexture"
,
false
)
);
m_uniformSampler
=
osg
::
ref_ptr
<
osg
::
Uniform
>
(
new
osg
::
Uniform
(
"tex"
,
0
)
);
m_uniformType
=
osg
::
ref_ptr
<
osg
::
Uniform
>
(
new
osg
::
Uniform
(
"type"
,
0
)
);
m_uniformThreshold
=
osg
::
ref_ptr
<
osg
::
Uniform
>
(
new
osg
::
Uniform
(
"threshold"
,
0.0
f
)
);
...
...
@@ -385,6 +420,7 @@ void WMFiberDisplay::initUniforms( osg::StateSet* rootState )
m_uniformDimY
=
osg
::
ref_ptr
<
osg
::
Uniform
>
(
new
osg
::
Uniform
(
"dimY"
,
1
)
);
m_uniformDimZ
=
osg
::
ref_ptr
<
osg
::
Uniform
>
(
new
osg
::
Uniform
(
"dimZ"
,
1
)
);
rootState
->
addUniform
(
m_uniformUseTexture
);
rootState
->
addUniform
(
m_uniformSampler
);
rootState
->
addUniform
(
m_uniformType
);
rootState
->
addUniform
(
m_uniformThreshold
);
...
...
@@ -393,9 +429,48 @@ void WMFiberDisplay::initUniforms( osg::StateSet* rootState )
rootState
->
addUniform
(
m_uniformDimX
);
rootState
->
addUniform
(
m_uniformDimY
);
rootState
->
addUniform
(
m_uniformDimZ
);
// cull box info
float
xMin
=
m_cullBox
->
getMinPos
()[
0
];
float
yMin
=
m_cullBox
->
getMinPos
()[
1
];
float
zMin
=
m_cullBox
->
getMinPos
()[
2
];
float
xMax
=
m_cullBox
->
getMaxPos
()[
0
];
float
yMax
=
m_cullBox
->
getMaxPos
()[
1
];
float
zMax
=
m_cullBox
->
getMaxPos
()[
2
];
m_uniformUseCullBox
=
osg
::
ref_ptr
<
osg
::
Uniform
>
(
new
osg
::
Uniform
(
"useCullBox"
,
false
)
);
m_uniformInsideCullBox
=
osg
::
ref_ptr
<
osg
::
Uniform
>
(
new
osg
::
Uniform
(
"insideCullBox"
,
false
)
);
m_uniformCullBoxLBX
=
osg
::
ref_ptr
<
osg
::
Uniform
>
(
new
osg
::
Uniform
(
"cullBoxLBX"
,
static_cast
<
float
>
(
xMin
)
)
);
m_uniformCullBoxLBY
=
osg
::
ref_ptr
<
osg
::
Uniform
>
(
new
osg
::
Uniform
(
"cullBoxLBY"
,
static_cast
<
float
>
(
yMin
)
)
);
m_uniformCullBoxLBZ
=
osg
::
ref_ptr
<
osg
::
Uniform
>
(
new
osg
::
Uniform
(
"cullBoxLBZ"
,
static_cast
<
float
>
(
zMin
)
)
);
m_uniformCullBoxUBX
=
osg
::
ref_ptr
<
osg
::
Uniform
>
(
new
osg
::
Uniform
(
"cullBoxUBX"
,
static_cast
<
float
>
(
xMax
)
)
);
m_uniformCullBoxUBY
=
osg
::
ref_ptr
<
osg
::
Uniform
>
(
new
osg
::
Uniform
(
"cullBoxUBY"
,
static_cast
<
float
>
(
yMax
)
)
);
m_uniformCullBoxUBZ
=
osg
::
ref_ptr
<
osg
::
Uniform
>
(
new
osg
::
Uniform
(
"cullBoxUBZ"
,
static_cast
<
float
>
(
zMax
)
)
);
rootState
->
addUniform
(
m_uniformUseCullBox
);
rootState
->
addUniform
(
m_uniformCullBoxLBX
);
rootState
->
addUniform
(
m_uniformCullBoxLBY
);
rootState
->
addUniform
(
m_uniformCullBoxLBZ
);
rootState
->
addUniform
(
m_uniformCullBoxUBX
);
rootState
->
addUniform
(
m_uniformCullBoxUBY
);
rootState
->
addUniform
(
m_uniformCullBoxUBZ
);
rootState
->
addUniform
(
m_uniformUseCullBox
);
rootState
->
addUniform
(
m_uniformInsideCullBox
);
}
void
WMFiberDisplay
::
notifyTextureChange
()
{
m_textureChanged
=
true
;
}
void
WMFiberDisplay
::
initCullBox
()
{
wmath
::
WPosition
crossHairPos
=
WKernel
::
getRunningKernel
()
->
getSelectionManager
()
->
getCrosshair
()
->
getPosition
();
wmath
::
WPosition
minROIPos
=
crossHairPos
-
wmath
::
WPosition
(
10.
,
10.
,
10.
);
wmath
::
WPosition
maxROIPos
=
crossHairPos
+
wmath
::
WPosition
(
10.
,
10.
,
10.
);
m_cullBox
=
osg
::
ref_ptr
<
WROIBox
>
(
new
WROIBox
(
minROIPos
,
maxROIPos
)
);
m_cullBox
->
setColor
(
osg
::
Vec4
(
1.0
,
0.
,
1.0
,
0.4
)
);
}
src/kernel/modules/fiberDisplay/WMFiberDisplay.h
View file @
f14d9b6b
...
...
@@ -31,13 +31,15 @@
#include "../../../dataHandler/datastructures/WFiberCluster.h"
#include "../../../dataHandler/WDataSetFibers.h"
#include "../../../graphicsEngine/WROI.h"
#include "../../../graphicsEngine/WROIBox.h"
#include "../../../graphicsEngine/WShader.h"
#include "../../WModule.h"
#include "../../WModuleInputData.h"
#include "WTubeDrawable.h"
/**
*
Test m
odule for drawing fibers
*
M
odule for drawing fibers
*
* \ingroup modules
*/
...
...
@@ -142,6 +144,11 @@ private:
WBoolFlag
m_noData
;
//!< Flag indicating whether there is data to display.
WPropGroup
m_cullBoxGroup
;
//!< property group for box culling
WPropBool
m_activateCullBox
;
//!< if true fibers are culled depending on a cull box
WPropBool
m_showCullBox
;
//!< Enable/Disable showing of the cull box
WPropBool
m_insideCullBox
;
//!< if true fibers inside the cull box are shown, outside if false
/**
* Input connector for a fiber dataset.
*/
...
...
@@ -190,6 +197,11 @@ private:
*/
bool
m_textureChanged
;
/**
* boolean to notify the shader to use the texture instead of glColor
*/
osg
::
ref_ptr
<
osg
::
Uniform
>
m_uniformUseTexture
;
/**
* uniform for type of texture
*/
...
...
@@ -214,15 +226,30 @@ private:
osg
::
ref_ptr
<
osg
::
Uniform
>
m_uniformDimY
;
//!< y dimension of the dataset for calculating the texture coord in the shader
osg
::
ref_ptr
<
osg
::
Uniform
>
m_uniformDimZ
;
//!< z dimension of the dataset for calculating the texture coord in the shader
osg
::
ref_ptr
<
osg
::
Uniform
>
m_uniformUseCullBox
;
//!< notify shader that cull box is activated
osg
::
ref_ptr
<
osg
::
Uniform
>
m_uniformInsideCullBox
;
//!< notify shader that fibers insider or outside cull box are shown
osg
::
ref_ptr
<
osg
::
Uniform
>
m_uniformCullBoxLBX
;
//!< cull box lower bound
osg
::
ref_ptr
<
osg
::
Uniform
>
m_uniformCullBoxLBY
;
//!< cull box lower bound
osg
::
ref_ptr
<
osg
::
Uniform
>
m_uniformCullBoxLBZ
;
//!< cull box lower bound
osg
::
ref_ptr
<
osg
::
Uniform
>
m_uniformCullBoxUBX
;
//!< cull box upper bound
osg
::
ref_ptr
<
osg
::
Uniform
>
m_uniformCullBoxUBY
;
//!< cull box upper bound
osg
::
ref_ptr
<
osg
::
Uniform
>
m_uniformCullBoxUBZ
;
//!< cull box upper bound
/**
* To avoid multiple instances of the fiber display.
*/
static
bool
m_fiberDisplayRunning
;
osg
::
ref_ptr
<
WROIBox
>
m_cullBox
;
//!< stores a pointer to the cull box
/**
* switches between fiber display and tube representation
* switches between fiber display and tube representation,
* texturing and box culling
* activates the neccesary shaders
*/
void
toggleTub
es
();
void
updateRenderMod
es
();
/**
* Enable disable global or local coloring
...
...
@@ -250,6 +277,12 @@ private:
*/
void
updateTexture
();
/**
* create a selection box to cull the fibers
*/
void
initCullBox
();
/**
* Node callback to handle updates properly
*/
...
...
@@ -269,7 +302,7 @@ private:
if
(
module
)
{
module
->
update
();
module
->
toggleTub
es
();
module
->
updateRenderMod
es
();
module
->
toggleColoring
();
}
traverse
(
node
,
nv
);
...
...
src/kernel/modules/fiberDisplay/shaders/WMFiberDisplay-Textured-fragment.glsl
View file @
f14d9b6b
varying
vec4
myColor
;
varying
vec4
VaryingTexCoord0
;
uniform
int
dimX
,
dimY
,
dimZ
;
uniform
sampler3D
tex
;
...
...
@@ -9,6 +8,16 @@ uniform int type;
uniform
float
threshold
;
uniform
int
cMap
;
uniform
bool
useTexture
;
uniform
bool
useCullBox
;
uniform
bool
insideCullBox
;
uniform
float
cullBoxLBX
;
uniform
float
cullBoxLBY
;
uniform
float
cullBoxLBZ
;
uniform
float
cullBoxUBX
;
uniform
float
cullBoxUBY
;
uniform
float
cullBoxUBZ
;
#include "WGEColorMaps.glsl"
#include "WGEUtils.glsl"
...
...
@@ -31,19 +40,43 @@ float lookupTex()
return
col1
.
r
;
}
void
checkCullBox
()
{
vec3
pos
=
VaryingTexCoord0
.
xyz
;
if
(
insideCullBox
)
{
if
(
pos
.
x
<
cullBoxLBX
||
pos
.
x
>
cullBoxUBX
)
discard
;
if
(
pos
.
y
<
cullBoxLBY
||
pos
.
y
>
cullBoxUBY
)
discard
;
if
(
pos
.
z
<
cullBoxLBZ
||
pos
.
z
>
cullBoxUBZ
)
discard
;
}
else
{
if
(
(
pos
.
x
>
cullBoxLBX
&&
pos
.
x
<
cullBoxUBX
)
&&
(
pos
.
y
>
cullBoxLBY
&&
pos
.
y
<
cullBoxUBY
)
&&
(
pos
.
z
>
cullBoxLBZ
&&
pos
.
z
<
cullBoxUBZ
)
)
discard
;
}
}
/*
* simple fragment shader that uses a texture on fibers
*/
void
main
()
{
vec4
color
=
vec4
(
1
.
0
);
float
value
=
lookupTex
();
if
(
useCullBox
)
checkCullBox
();
colorMap
(
color
.
rgb
,
value
,
cMap
)
;
vec4
color
=
myColor
;
color
.
a
=
1
.
0
;
if
(
useTexture
)
{
float
value
=
lookupTex
();
colorMap
(
color
.
rgb
,
value
,
cMap
);
color
.
a
=
1
.
0
;
}
gl_FragColor
=
color
;
}
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