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
d47a38de
Commit
d47a38de
authored
May 11, 2011
by
Alexander Wiebel
Browse files
[FIX] adapted Line Guided Slice to new color mapping to make it compile again
parent
57df4848
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
28 additions
and
225 deletions
+28
-225
src/modules/lineGuidedSlice/WMLineGuidedSlice.cpp
src/modules/lineGuidedSlice/WMLineGuidedSlice.cpp
+18
-136
src/modules/lineGuidedSlice/WMLineGuidedSlice.h
src/modules/lineGuidedSlice/WMLineGuidedSlice.h
+0
-28
src/modules/lineGuidedSlice/shaders/WMLineGuidedSlice-fragment.glsl
...s/lineGuidedSlice/shaders/WMLineGuidedSlice-fragment.glsl
+5
-44
src/modules/lineGuidedSlice/shaders/WMLineGuidedSlice-vertex.glsl
...les/lineGuidedSlice/shaders/WMLineGuidedSlice-vertex.glsl
+4
-16
src/modules/modules-others.toolbox
src/modules/modules-others.toolbox
+1
-1
No files found.
src/modules/lineGuidedSlice/WMLineGuidedSlice.cpp
View file @
d47a38de
...
...
@@ -31,11 +31,11 @@
#include "../../common/WLogger.h"
#include "../../dataHandler/datastructures/WFiberCluster.h"
#include "../../dataHandler/WDataHandler.h"
#include "../../dataHandler/WDataTexture3D.h"
#include "../../dataHandler/WSubject.h"
#include "../../graphicsEngine/
shaders/WGEShader
.h"
#include "../../graphicsEngine/
WGEColormapping
.h"
#include "../../graphicsEngine/WGEGeodeUtils.h"
#include "../../graphicsEngine/WGEUtils.h"
#include "../../graphicsEngine/shaders/WGEShader.h"
#include "../../kernel/WKernel.h"
#include "WMLineGuidedSlice.h"
#include "WMLineGuidedSlice.xpm"
...
...
@@ -44,10 +44,8 @@ W_LOADABLE_MODULE( WMLineGuidedSlice )
WMLineGuidedSlice
::
WMLineGuidedSlice
()
:
WModule
(),
m_textureChanged
(
true
),
m_isPicked
(
false
)
{
m_shader
=
osg
::
ref_ptr
<
WGEShader
>
(
new
WGEShader
(
"WMLineGuidedSlice"
)
);
}
WMLineGuidedSlice
::~
WMLineGuidedSlice
()
...
...
@@ -109,11 +107,6 @@ void WMLineGuidedSlice::moduleMain()
// signal ready state
ready
();
// now, to watch changing/new textures use WSubject's change condition
boost
::
signals2
::
connection
con
=
WDataHandler
::
getDefaultSubject
()
->
getChangeCondition
()
->
subscribeSignal
(
boost
::
bind
(
&
WMLineGuidedSlice
::
notifyTextureChange
,
this
)
);
m_rootNode
=
osg
::
ref_ptr
<
WGEGroupNode
>
(
new
WGEGroupNode
()
);
while
(
!
m_shutdownFlag
()
)
// loop until the module container requests the module to quit
...
...
@@ -133,14 +126,6 @@ void WMLineGuidedSlice::moduleMain()
// clean up stuff
WKernel
::
getRunningKernel
()
->
getGraphicsEngine
()
->
getScene
()
->
remove
(
m_rootNode
);
// deregister from WSubject's change condition
con
.
disconnect
();
}
void
WMLineGuidedSlice
::
notifyTextureChange
()
{
m_textureChanged
=
true
;
}
void
WMLineGuidedSlice
::
updateCenterLine
()
...
...
@@ -174,11 +159,14 @@ void WMLineGuidedSlice::create()
m_sliceNode
->
addDrawable
(
createGeometry
()
);
m_rootNode
->
insert
(
m_sliceNode
);
m_shader
->
apply
(
m_sliceNode
);
osg
::
ref_ptr
<
WGEShader
>
shader
;
shader
=
osg
::
ref_ptr
<
WGEShader
>
(
new
WGEShader
(
"WMLineGuidedSlice"
,
m_localPath
)
);
shader
->
apply
(
m_sliceNode
);
osg
::
StateSet
*
sliceState
=
m_sliceNode
->
getOrCreateStateSet
();
initUniforms
(
sliceState
);
// Colormapping
WGEColormapping
::
apply
(
m_sliceNode
,
shader
);
osg
::
StateSet
*
sliceState
=
m_sliceNode
->
getOrCreateStateSet
();
sliceState
->
setMode
(
GL_BLEND
,
osg
::
StateAttribute
::
ON
);
m_sliceNode
->
setUserData
(
this
);
...
...
@@ -238,42 +226,19 @@ osg::ref_ptr<osg::Geometry> WMLineGuidedSlice::createGeometry()
osg
::
Vec3Array
*
sliceVertices
=
new
osg
::
Vec3Array
;
// { TODO(all): this is deprecated.
// grab a list of data textures
std
::
vector
<
boost
::
shared_ptr
<
WDataTexture3D
>
>
tex
=
WDataHandler
::
getDefaultSubject
()
->
getDataTextures
(
true
);
const
double
radius
=
100
;
std
::
vector
<
WPosition
>
vertices
;
vertices
.
push_back
(
startPos
+
(
sliceVec1
+
sliceVec2
)
*
radius
);
vertices
.
push_back
(
startPos
+
(
-
1
*
sliceVec1
+
sliceVec2
)
*
radius
);
vertices
.
push_back
(
startPos
+
(
-
1
*
sliceVec1
-
sliceVec2
)
*
radius
);
vertices
.
push_back
(
startPos
+
(
sliceVec1
-
sliceVec2
)
*
radius
);
if
(
tex
.
size
()
>
0
)
const
size_t
nbVerts
=
4
;
for
(
size_t
i
=
0
;
i
<
nbVerts
;
++
i
)
{
const
double
radius
=
100
;
std
::
vector
<
WPosition
>
vertices
;
vertices
.
push_back
(
startPos
+
(
sliceVec1
+
sliceVec2
)
*
radius
);
vertices
.
push_back
(
startPos
+
(
-
1
*
sliceVec1
+
sliceVec2
)
*
radius
);
vertices
.
push_back
(
startPos
+
(
-
1
*
sliceVec1
-
sliceVec2
)
*
radius
);
vertices
.
push_back
(
startPos
+
(
sliceVec1
-
sliceVec2
)
*
radius
);
const
size_t
nbVerts
=
4
;
for
(
size_t
i
=
0
;
i
<
nbVerts
;
++
i
)
{
sliceVertices
->
push_back
(
vertices
[
i
]
);
}
sliceGeometry
->
setVertexArray
(
sliceVertices
);
int
counter
=
0
;
for
(
std
::
vector
<
boost
::
shared_ptr
<
WDataTexture3D
>
>::
const_iterator
iter
=
tex
.
begin
();
iter
!=
tex
.
end
();
++
iter
)
{
boost
::
shared_ptr
<
WGridRegular3D
>
grid
=
(
*
iter
)
->
getGrid
();
osg
::
Vec3Array
*
texCoords
=
new
osg
::
Vec3Array
;
texCoords
->
clear
();
for
(
size_t
i
=
0
;
i
<
nbVerts
;
++
i
)
{
texCoords
->
push_back
(
grid
->
worldCoordToTexCoord
(
vertices
[
i
]
+
WVector3d
(
0.5
,
0.5
,
0.5
)
)
);
}
sliceGeometry
->
setTexCoordArray
(
counter
,
texCoords
);
++
counter
;
}
sliceVertices
->
push_back
(
vertices
[
i
]
);
}
// }
sliceGeometry
->
setVertexArray
(
sliceVertices
);
osg
::
DrawElementsUInt
*
quad
=
new
osg
::
DrawElementsUInt
(
osg
::
PrimitiveSet
::
QUADS
,
0
);
quad
->
push_back
(
3
);
...
...
@@ -295,89 +260,6 @@ void WMLineGuidedSlice::updateGeometry()
osg
::
ref_ptr
<
osg
::
Drawable
>
old
=
osg
::
ref_ptr
<
osg
::
Drawable
>
(
m_sliceNode
->
getDrawable
(
0
)
);
m_sliceNode
->
replaceDrawable
(
old
,
sliceGeometry
);
// { TODO(all): this is deprecated.
std
::
vector
<
boost
::
shared_ptr
<
WDataTexture3D
>
>
tex
=
WDataHandler
::
getDefaultSubject
()
->
getDataTextures
(
true
);
// }
slock
.
unlock
();
}
void
WMLineGuidedSlice
::
updateTextures
()
{
osg
::
StateSet
*
sliceState
=
m_sliceNode
->
getOrCreateStateSet
();
if
(
m_textureChanged
)
{
m_textureChanged
=
false
;
// { TODO(all): this is deprecated.
// grab a list of data textures
std
::
vector
<
boost
::
shared_ptr
<
WDataTexture3D
>
>
tex
=
WDataHandler
::
getDefaultSubject
()
->
getDataTextures
(
true
);
if
(
tex
.
size
()
>
0
)
{
// reset all uniforms
for
(
int
i
=
0
;
i
<
2
;
++
i
)
{
m_typeUniforms
[
i
]
->
set
(
0
);
}
// for each texture -> apply
int
c
=
0
;
for
(
std
::
vector
<
boost
::
shared_ptr
<
WDataTexture3D
>
>::
const_iterator
iter
=
tex
.
begin
();
iter
!=
tex
.
end
();
++
iter
)
{
osg
::
ref_ptr
<
osg
::
Texture3D
>
texture3D
=
(
*
iter
)
->
getTexture
();
sliceState
->
setTextureAttributeAndModes
(
c
,
texture3D
,
osg
::
StateAttribute
::
ON
);
// set threshold/opacity as uniforms
float
t
=
(
*
iter
)
->
getThreshold
()
/
255.0
;
float
a
=
(
*
iter
)
->
getAlpha
();
m_typeUniforms
[
c
]
->
set
(
(
*
iter
)
->
getDataType
()
);
m_thresholdUniforms
[
c
]
->
set
(
t
);
m_alphaUniforms
[
c
]
->
set
(
a
);
++
c
;
}
bool
useTexture
=
m_properties
->
getProperty
(
"Use texture"
)
->
toPropBool
()
->
get
();
sliceState
->
addUniform
(
osg
::
ref_ptr
<
osg
::
Uniform
>
(
new
osg
::
Uniform
(
"useTexture"
,
useTexture
)
)
);
}
// }
}
m_highlightUniform
->
set
(
m_isPicked
);
m_sliceNode
->
getOrCreateStateSet
()
->
merge
(
*
sliceState
);
}
void
WMLineGuidedSlice
::
initUniforms
(
osg
::
StateSet
*
sliceState
)
{
boost
::
shared_lock
<
boost
::
shared_mutex
>
slock
;
slock
=
boost
::
shared_lock
<
boost
::
shared_mutex
>
(
m_updateLock
);
m_typeUniforms
.
push_back
(
osg
::
ref_ptr
<
osg
::
Uniform
>
(
new
osg
::
Uniform
(
"type0"
,
0
)
)
);
m_typeUniforms
.
push_back
(
osg
::
ref_ptr
<
osg
::
Uniform
>
(
new
osg
::
Uniform
(
"type1"
,
0
)
)
);
m_alphaUniforms
.
push_back
(
osg
::
ref_ptr
<
osg
::
Uniform
>
(
new
osg
::
Uniform
(
"alpha0"
,
1.0
f
)
)
);
m_alphaUniforms
.
push_back
(
osg
::
ref_ptr
<
osg
::
Uniform
>
(
new
osg
::
Uniform
(
"alpha1"
,
1.0
f
)
)
);
m_thresholdUniforms
.
push_back
(
osg
::
ref_ptr
<
osg
::
Uniform
>
(
new
osg
::
Uniform
(
"threshold0"
,
0.0
f
)
)
);
m_thresholdUniforms
.
push_back
(
osg
::
ref_ptr
<
osg
::
Uniform
>
(
new
osg
::
Uniform
(
"threshold1"
,
0.0
f
)
)
);
m_samplerUniforms
.
push_back
(
osg
::
ref_ptr
<
osg
::
Uniform
>
(
new
osg
::
Uniform
(
"tex0"
,
0
)
)
);
m_samplerUniforms
.
push_back
(
osg
::
ref_ptr
<
osg
::
Uniform
>
(
new
osg
::
Uniform
(
"tex1"
,
1
)
)
);
for
(
int
i
=
0
;
i
<
2
;
++
i
)
{
sliceState
->
addUniform
(
m_typeUniforms
[
i
]
);
sliceState
->
addUniform
(
m_thresholdUniforms
[
i
]
);
sliceState
->
addUniform
(
m_alphaUniforms
[
i
]
);
sliceState
->
addUniform
(
m_samplerUniforms
[
i
]
);
}
m_highlightUniform
=
osg
::
ref_ptr
<
osg
::
Uniform
>
(
new
osg
::
Uniform
(
"highlighted"
,
0
)
);
m_sliceNode
->
getOrCreateStateSet
()
->
addUniform
(
m_highlightUniform
);
slock
.
unlock
();
}
src/modules/lineGuidedSlice/WMLineGuidedSlice.h
View file @
d47a38de
...
...
@@ -102,26 +102,11 @@ protected:
private:
/**
* Used as callback which simply sets m_textureChanged to true. Called by WSubject whenever the datasets change.
*/
void
notifyTextureChange
();
/**
* True when textures have changed.
*/
bool
m_textureChanged
;
/**
* Updates the positions of the slice
*/
void
updateGeometry
();
/**
* Uppdates textures and shader parameters
*/
void
updateTextures
();
/**
* Creates the inital geometry.
*/
...
...
@@ -143,12 +128,6 @@ private:
*/
osg
::
ref_ptr
<
osg
::
Geometry
>
createGeometry
();
/**
* Creates and initializes the uniform parameters for the shader
* \param rootState The uniforms will be applied to this state.
*/
void
initUniforms
(
osg
::
StateSet
*
rootState
);
WPropDouble
m_pos
;
//!< Slice position along line.
WVector2d
m_oldPixelPosition
;
//!< Caches the old picked position to a allow for cmoparison
...
...
@@ -159,13 +138,7 @@ private:
osg
::
ref_ptr
<
WGEGroupNode
>
m_rootNode
;
//!< The root node for this module.
osg
::
ref_ptr
<
osg
::
Geode
>
m_sliceNode
;
//!< OSG node for slice.
osg
::
ref_ptr
<
osg
::
Geode
>
m_centerLineGeode
;
//!< OSG center line of the current cluster geode.
osg
::
ref_ptr
<
WGEShader
>
m_shader
;
//!< The shader object for this module.
boost
::
shared_mutex
m_updateLock
;
//!< Lock to prevent concurrent threads trying to update the osg node.
std
::
vector
<
osg
::
ref_ptr
<
osg
::
Uniform
>
>
m_typeUniforms
;
//!< Vector of uniforms for type of texture.
std
::
vector
<
osg
::
ref_ptr
<
osg
::
Uniform
>
>
m_alphaUniforms
;
//!< Vector of alpha values per texture.
std
::
vector
<
osg
::
ref_ptr
<
osg
::
Uniform
>
>
m_thresholdUniforms
;
//!< Vector of thresholds per texture.
std
::
vector
<
osg
::
ref_ptr
<
osg
::
Uniform
>
>
m_samplerUniforms
;
//!< Vector of samplers.
osg
::
ref_ptr
<
osg
::
Uniform
>
m_highlightUniform
;
//!< Determines whether the slice is highlighted.
boost
::
shared_ptr
<
WFiber
>
m_centerLine
;
//!< The line that guides the slice.
...
...
@@ -188,7 +161,6 @@ private:
if
(
module
)
{
module
->
updateGeometry
();
module
->
updateTextures
();
}
traverse
(
node
,
nv
);
}
...
...
src/modules/lineGuidedSlice/shaders/WMLineGuidedSlice-fragment.glsl
View file @
d47a38de
...
...
@@ -22,56 +22,17 @@
//
//---------------------------------------------------------------------------
varying
vec4
VaryingTexCoord0
;
varying
vec4
VaryingTexCoord1
;
uniform
sampler3D
tex0
;
uniform
sampler3D
tex1
;
uniform
float
threshold0
;
uniform
float
threshold1
;
uniform
int
type0
;
uniform
int
type1
;
uniform
float
alpha0
;
uniform
float
alpha1
;
void
parameterColorMap
(
inout
vec4
col
,
in
sampler3D
tex
,
in
vec3
coords
)
{
vec3
val
=
vec3
(
0
.
0
);
val
=
clamp
(
texture3D
(
tex
,
coords
).
rgb
,
0
.
0
,
1
.
0
);
float
value
=
val
.
x
;
// get a float
clamp
(
0
.
1
,
0
.
9
,
value
);
value
=
(
value
-
0
.
1
)
*
0
.
8
;
// scale to [0,1]
col
.
r
=
0
.;
col
.
g
=
value
;
col
.
b
=
1
.;
col
.
a
=
1
.;
}
#include "WGEColormapping-fragment.glsl"
void
main
()
{
vec4
col
=
vec4
(
0
.
0
,
0
.
0
,
0
.
0
,
1
.
0
);
vec4
colFib
=
vec4
(
0
.
0
,
0
.
0
,
0
.
0
,
1
.
0
);
vec4
colFA
=
vec4
(
0
.
0
,
0
.
0
,
0
.
0
,
1
.
0
);
if
(
type1
>
0
)
{
parameterColorMap
(
colFA
,
tex1
,
VaryingTexCoord1
.
xyz
);
}
col
=
clamp
(
colFA
,
0
.
0
,
1
.
0
);
if
(
texture3D
(
tex0
,
VaryingTexCoord0
.
xyz
).
r
<
0
.
2
)
// TODO(wiebel): We need to access two textures here. One for the quantity to show, one for cutting out the interesting part.
col
=
colormapping
();
if
(
col
.
a
==
0
)
{
// if(
// VaryingTexCoord0.x < 0.001 || VaryingTexCoord0.x > 0.9
// || VaryingTexCoord0.y < 0.001 || VaryingTexCoord0.y > 0.3
// || VaryingTexCoord0.z < 0.001 || VaryingTexCoord0.z > 0.9
// )
discard
;
// else
// col = vec4( 1, 1, 1, 1);
discard
;
}
gl_FragColor
=
col
;
}
src/modules/lineGuidedSlice/shaders/WMLineGuidedSlice-vertex.glsl
View file @
d47a38de
...
...
@@ -22,24 +22,12 @@
//
//---------------------------------------------------------------------------
varying
vec4
VaryingTexCoord0
;
varying
vec4
VaryingTexCoord1
;
varying
vec4
VaryingTexCoord2
;
varying
vec4
VaryingTexCoord3
;
varying
vec4
VaryingTexCoord4
;
varying
vec4
VaryingTexCoord5
;
varying
vec4
VaryingTexCoord6
;
varying
vec4
VaryingTexCoord7
;
#include "WGEColormapping-vertex.glsl"
void
main
()
{
VaryingTexCoord0
=
gl_MultiTexCoord0
;
VaryingTexCoord1
=
gl_MultiTexCoord1
;
VaryingTexCoord2
=
gl_MultiTexCoord2
;
VaryingTexCoord3
=
gl_MultiTexCoord3
;
VaryingTexCoord4
=
gl_MultiTexCoord4
;
VaryingTexCoord5
=
gl_MultiTexCoord5
;
VaryingTexCoord6
=
gl_MultiTexCoord6
;
VaryingTexCoord7
=
gl_MultiTexCoord7
;
// prepare colormapping
colormapping
();
gl_Position
=
ftransform
();
}
src/modules/modules-others.toolbox
View file @
d47a38de
...
...
@@ -24,7 +24,7 @@ ADD_SUBDIRECTORY( fiberSelection )
ADD_SUBDIRECTORY( fiberTransform )
ADD_SUBDIRECTORY( gaussProcesses )
ADD_SUBDIRECTORY( imageExtractor )
#
ADD_SUBDIRECTORY( lineGuidedSlice )
ADD_SUBDIRECTORY( lineGuidedSlice )
ADD_SUBDIRECTORY( probTractDisplay )
ADD_SUBDIRECTORY( probTractDisplaySP )
ADD_SUBDIRECTORY( scalarOperator )
...
...
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