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
2d582c2c
Commit
2d582c2c
authored
Mar 10, 2010
by
schurade
Browse files
[FIX] deactivate tube shader when only displaying fibers
parent
36664d0c
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
81 additions
and
29 deletions
+81
-29
src/dataHandler/WDataSetFibers.cpp
src/dataHandler/WDataSetFibers.cpp
+15
-15
src/graphicsEngine/WShader.cpp
src/graphicsEngine/WShader.cpp
+25
-2
src/graphicsEngine/WShader.h
src/graphicsEngine/WShader.h
+14
-0
src/modules/fiberDisplay/WMFiberDisplay.cpp
src/modules/fiberDisplay/WMFiberDisplay.cpp
+3
-2
src/modules/fiberDisplay/WTubeDrawable.cpp
src/modules/fiberDisplay/WTubeDrawable.cpp
+21
-9
src/modules/fiberDisplay/WTubeDrawable.h
src/modules/fiberDisplay/WTubeDrawable.h
+3
-1
No files found.
src/dataHandler/WDataSetFibers.cpp
View file @
2d582c2c
...
...
@@ -74,12 +74,12 @@ WDataSetFibers::WDataSetFibers( boost::shared_ptr< std::vector< float > >vertice
float
lastx
,
lasty
,
lastz
;
for
(
size_t
i
=
0
;
i
<
m_lineLengths
->
size
();
++
i
)
{
x1
=
m_vertices
->
at
(
pc
)
;
y1
=
m_vertices
->
at
(
pc
+
1
)
;
z1
=
m_vertices
->
at
(
pc
+
2
)
;
x2
=
m_vertices
->
at
(
pc
+
m_lineLengths
->
at
(
i
)
*
3
-
3
)
;
y2
=
m_vertices
->
at
(
pc
+
m_lineLengths
->
at
(
i
)
*
3
-
2
)
;
z2
=
m_vertices
->
at
(
pc
+
m_lineLengths
->
at
(
i
)
*
3
-
1
)
;
x1
=
(
*
m_vertices
)[
pc
]
;
y1
=
(
*
m_vertices
)[
pc
+
1
]
;
z1
=
(
*
m_vertices
)[
pc
+
2
]
;
x2
=
(
*
m_vertices
)[
pc
+
(
*
m_lineLengths
)[
i
]
*
3
-
3
]
;
y2
=
(
*
m_vertices
)[
pc
+
(
*
m_lineLengths
)[
i
]
*
3
-
2
]
;
z2
=
(
*
m_vertices
)[
pc
+
(
*
m_lineLengths
)[
i
]
*
3
-
1
]
;
r
=
(
x1
)
-
(
x2
);
g
=
(
y1
)
-
(
y2
);
...
...
@@ -96,18 +96,18 @@ WDataSetFibers::WDataSetFibers( boost::shared_ptr< std::vector< float > >vertice
g
*=
1.0
/
norm
;
b
*=
1.0
/
norm
;
lastx
=
m_vertices
->
at
(
pc
)
+
(
m_vertices
->
at
(
pc
)
-
m_vertices
->
at
(
pc
+
3
)
);
lasty
=
m_vertices
->
at
(
pc
+
1
)
+
(
m_vertices
->
at
(
pc
+
1
)
-
m_vertices
->
at
(
pc
+
4
)
);
lastz
=
m_vertices
->
at
(
pc
+
2
)
+
(
m_vertices
->
at
(
pc
+
2
)
-
m_vertices
->
at
(
pc
+
5
)
);
lastx
=
(
*
m_vertices
)[
pc
]
+
(
(
*
m_vertices
)[
pc
]
-
(
*
m_vertices
)[
pc
+
3
]
);
lasty
=
(
*
m_vertices
)[
pc
+
1
]
+
(
(
*
m_vertices
)[
pc
+
1
]
-
(
*
m_vertices
)[
pc
+
4
]
);
lastz
=
(
*
m_vertices
)[
pc
+
2
]
+
(
(
*
m_vertices
)[
pc
+
2
]
-
(
*
m_vertices
)[
pc
+
5
]
);
for
(
size_t
j
=
0
;
j
<
m_lineLengths
->
at
(
i
);
++
j
)
{
rr
=
lastx
-
m_vertices
->
at
(
pc
)
;
gg
=
lasty
-
m_vertices
->
at
(
pc
+
1
)
;
bb
=
lastz
-
m_vertices
->
at
(
pc
+
2
)
;
lastx
=
m_vertices
->
at
(
pc
)
;
lasty
=
m_vertices
->
at
(
pc
+
1
)
;
lastz
=
m_vertices
->
at
(
pc
+
2
)
;
rr
=
lastx
-
(
*
m_vertices
)[
pc
]
;
gg
=
lasty
-
(
*
m_vertices
)[
pc
+
1
]
;
bb
=
lastz
-
(
*
m_vertices
)[
pc
+
2
]
;
lastx
=
(
*
m_vertices
)[
pc
]
;
lasty
=
(
*
m_vertices
)[
pc
+
1
]
;
lastz
=
(
*
m_vertices
)[
pc
+
2
]
;
// if ( rr < 0.0 )
// rr *= -1.0;
...
...
src/graphicsEngine/WShader.cpp
View file @
2d582c2c
...
...
@@ -46,7 +46,8 @@ WShader::WShader( std::string name ):
osg
::
Program
(),
m_shaderPath
(
WGraphicsEngine
::
getGraphicsEngine
()
->
getShaderPath
()
),
m_name
(
name
),
m_reload
(
true
)
m_reload
(
true
),
m_deactivated
(
false
)
{
// create shader
m_vertexShader
=
osg
::
ref_ptr
<
osg
::
Shader
>
(
new
osg
::
Shader
(
osg
::
Shader
::
VERTEX
)
);
...
...
@@ -68,16 +69,30 @@ WShader::~WShader()
}
void
WShader
::
apply
(
osg
::
ref_ptr
<
osg
::
Node
>
node
)
{
// set the shader attribute
// NOTE: the attribute is protected to avoid father nodes overwriting it
osg
::
StateSet
*
rootState
=
node
->
getOrCreateStateSet
();
rootState
->
setAttributeAndModes
(
this
,
osg
::
StateAttribute
::
ON
|
osg
::
StateAttribute
::
PROTECTED
);
m_deactivated
=
false
;
m_reload
=
true
;
// add a custom callback which actually sets and updated the shader.
node
->
addUpdateCallback
(
osg
::
ref_ptr
<
SafeUpdaterCallback
>
(
new
SafeUpdaterCallback
(
this
)
)
);
}
void
WShader
::
deactivate
(
osg
::
ref_ptr
<
osg
::
Node
>
node
)
{
// set the shader attribute
// NOTE: the attribute is protected to avoid father nodes overwriting it
osg
::
StateSet
*
rootState
=
node
->
getOrCreateStateSet
();
rootState
->
setAttributeAndModes
(
this
,
osg
::
StateAttribute
::
ON
|
osg
::
StateAttribute
::
PROTECTED
);
m_deactivated
=
true
;
// add a custom callback which actually sets and updated the shader.
node
->
addUpdateCallback
(
osg
::
ref_ptr
<
SafeUpdaterCallback
>
(
new
SafeUpdaterCallback
(
this
)
)
);
}
void
WShader
::
reload
()
{
m_reload
=
true
;
...
...
@@ -91,7 +106,15 @@ WShader::SafeUpdaterCallback::SafeUpdaterCallback( WShader* shader ):
void
WShader
::
SafeUpdaterCallback
::
operator
()(
osg
::
Node
*
node
,
osg
::
NodeVisitor
*
nv
)
{
// is it needed to do something here?
if
(
m_shader
->
m_reload
)
if
(
m_shader
->
m_deactivated
)
{
// remove the shaders
m_shader
->
removeShader
(
m_shader
->
m_vertexShader
);
m_shader
->
removeShader
(
m_shader
->
m_fragmentShader
);
m_shader
->
removeShader
(
m_shader
->
m_geometryShader
);
}
else
if
(
m_shader
->
m_reload
)
{
try
{
...
...
src/graphicsEngine/WShader.h
View file @
2d582c2c
...
...
@@ -61,6 +61,15 @@ public:
*/
virtual
void
apply
(
osg
::
ref_ptr
<
osg
::
Node
>
node
);
/**
* Apply this shader to the specified node. Use this method to ensure, that reload events can be handled properly during the
* update cycle.
*
* \param node the node where the program is registered to.
*/
virtual
void
deactivate
(
osg
::
ref_ptr
<
osg
::
Node
>
node
);
/**
* Initiate a reload of the shader during the next update cycle.
*/
...
...
@@ -111,6 +120,11 @@ protected:
*/
bool
m_reload
;
/**
* Flag denoting whether a shader should be deactivated.
*/
bool
m_deactivated
;
/**
* Connection object to the reload signal from WGraphbicsEngine.
*/
...
...
src/modules/fiberDisplay/WMFiberDisplay.cpp
View file @
2d582c2c
...
...
@@ -132,7 +132,7 @@ void WMFiberDisplay::update()
if
(
WKernel
::
getRunningKernel
()
->
getRoiManager
()
->
isDirty
()
)
{
m_tubeDrawable
->
dirtyDisplayList
();
//
m_tubeDrawable->dirtyDisplayList();
}
slock
.
unlock
();
...
...
@@ -145,6 +145,7 @@ void WMFiberDisplay::create()
m_tubeDrawable
=
osg
::
ref_ptr
<
WTubeDrawable
>
(
new
WTubeDrawable
);
m_tubeDrawable
->
setDataset
(
m_dataset
);
m_tubeDrawable
->
setUseDisplayList
(
false
);
osg
::
ref_ptr
<
osg
::
Geode
>
geode
=
osg
::
ref_ptr
<
osg
::
Geode
>
(
new
osg
::
Geode
);
geode
->
addDrawable
(
m_tubeDrawable
);
...
...
@@ -207,7 +208,6 @@ void WMFiberDisplay::toggleTubes()
{
m_tubeDrawable
->
setUseTubes
(
true
);
m_tubeDrawable
->
dirtyDisplayList
();
m_shader
->
apply
(
m_osgNode
);
osg
::
ref_ptr
<
osg
::
Uniform
>
(
new
osg
::
Uniform
(
"globalColor"
,
1
)
);
osg
::
StateSet
*
rootState
=
m_osgNode
->
getOrCreateStateSet
();
...
...
@@ -217,6 +217,7 @@ void WMFiberDisplay::toggleTubes()
{
m_tubeDrawable
->
setUseTubes
(
false
);
m_tubeDrawable
->
dirtyDisplayList
();
m_shader
->
deactivate
(
m_osgNode
);
}
}
}
...
...
src/modules/fiberDisplay/WTubeDrawable.cpp
View file @
2d582c2c
...
...
@@ -38,7 +38,7 @@ WTubeDrawable::WTubeDrawable():
m_useTubes
(
false
),
m_globalColoring
(
true
)
{
//
setSupportsDisplayList
(false);
setSupportsDisplayList
(
false
);
// This contructor intentionally left blank. Duh.
}
...
...
@@ -70,7 +70,7 @@ osg::Object* WTubeDrawable::clone( const osg::CopyOp& copyop ) const
// That said, the example below shows how to change the OpenGL state in
// these rare cases in which it is necessary. But always keep in mind:
// *Change the OpenGL state only if strictly necessary*.
void
WTubeDrawable
::
drawImplementation
(
osg
::
RenderInfo
&
/*
renderInfo
*/
)
const
void
WTubeDrawable
::
drawImplementation
(
osg
::
RenderInfo
&
renderInfo
)
const
//NOLINT
{
if
(
m_useTubes
)
{
...
...
@@ -78,7 +78,7 @@ void WTubeDrawable::drawImplementation( osg::RenderInfo& /*renderInfo*/ ) const
}
else
{
drawFibers
();
drawFibers
(
renderInfo
);
}
}
...
...
@@ -102,7 +102,7 @@ bool WTubeDrawable::getColoringMode() const
return
m_globalColoring
;
}
void
WTubeDrawable
::
drawFibers
(
)
const
void
WTubeDrawable
::
drawFibers
(
osg
::
RenderInfo
&
renderInfo
)
const
//NOLINT
{
boost
::
shared_ptr
<
std
::
vector
<
size_t
>
>
startIndexes
=
m_dataset
->
getLineStartIndexes
();
boost
::
shared_ptr
<
std
::
vector
<
size_t
>
>
pointsPerLine
=
m_dataset
->
getLineLengths
();
...
...
@@ -110,21 +110,33 @@ void WTubeDrawable::drawFibers() const
boost
::
shared_ptr
<
std
::
vector
<
float
>
>
colors
=
(
m_globalColoring
?
m_dataset
->
getGlobalColors
()
:
m_dataset
->
getLocalColors
()
);
boost
::
shared_ptr
<
std
::
vector
<
bool
>
>
active
=
WKernel
::
getRunningKernel
()
->
getRoiManager
()
->
getBitField
();
for
(
size_t
i
=
0
;
i
<
active
->
size
();
++
i
)
// glEnableClientState( GL_VERTEX_ARRAY );
// glEnableClientState( GL_COLOR_ARRAY );
//
// glVertexPointer( 3, GL_FLOAT, 0, &(*verts)[0] );
// glColorPointer( 3, GL_FLOAT, 0, &(*colors)[0] );
for
(
size_t
i
=
0
;
i
<
active
->
size
();
++
i
)
{
if
(
active
->
at
(
i
)
)
if
(
(
*
active
)[
i
]
)
{
//glDrawArrays( GL_LINE_STRIP, (*startIndexes)[i] * 3, (*pointsPerLine)[i] );
glBegin
(
GL_LINE_STRIP
);
int
idx
=
startIndexes
->
at
(
i
)
*
3
;
int
idx
=
(
*
startIndexes
)[
i
]
*
3
;
for
(
size_t
k
=
0
;
k
<
pointsPerLine
->
at
(
i
);
++
k
)
{
glColor3f
(
colors
->
at
(
idx
),
colors
->
at
(
idx
+
1
),
colors
->
at
(
idx
+
2
)
);
glVertex3f
(
verts
->
at
(
idx
),
verts
->
at
(
idx
+
1
),
verts
->
at
(
idx
+
2
)
);
glColor3f
(
(
*
colors
)[
idx
],
(
*
colors
)[
idx
+
1
],
(
*
colors
)[
idx
+
2
]
);
glVertex3f
(
(
*
verts
)[
idx
],
(
*
verts
)[
idx
+
1
],
(
*
verts
)[
idx
+
2
]
);
idx
+=
3
;
}
glEnd
();
}
}
//std::cout << "huhu4" << std::endl;
// glDisableClientState( GL_VERTEX_ARRAY );
// glDisableClientState( GL_COLOR_ARRAY );
}
void
WTubeDrawable
::
drawTubes
()
const
...
...
src/modules/fiberDisplay/WTubeDrawable.h
View file @
2d582c2c
...
...
@@ -120,8 +120,10 @@ protected:
private:
/**
* Draw fibers as ordinary lines.
*
* \param renderInfo
*/
void
drawFibers
(
)
const
;
void
drawFibers
(
osg
::
RenderInfo
&
renderInfo
)
const
;
//NOLINT
/**
* Draw fibers as fake tubes.
...
...
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