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
e37a6943
Commit
e37a6943
authored
Jan 29, 2010
by
Alexander Wiebel
Browse files
[FIX] ROIBox now uses nodecallback. This is more secure
parent
455910b3
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
67 additions
and
15 deletions
+67
-15
src/graphicsEngine/WROI.h
src/graphicsEngine/WROI.h
+2
-3
src/graphicsEngine/WROIBox.cpp
src/graphicsEngine/WROIBox.cpp
+28
-8
src/graphicsEngine/WROIBox.h
src/graphicsEngine/WROIBox.h
+37
-4
No files found.
src/graphicsEngine/WROI.h
View file @
e37a6943
...
...
@@ -54,10 +54,9 @@ private:
bool
m_useColor
;
//!< Indicated whether m_color should be used for display.
/**
* updates the graphics
* \param text text info from pick
* updates the graphics. Remember that this shoudl only be called from a node callback
*/
virtual
void
updateGFX
(
std
::
string
text
)
=
0
;
virtual
void
updateGFX
()
=
0
;
};
#endif // WROI_H
src/graphicsEngine/WROIBox.cpp
View file @
e37a6943
...
...
@@ -111,7 +111,8 @@ void setVertices( osg::Vec3Array* vertices, wmath::WPosition minPos, wmath::WPos
WROIBox
::
WROIBox
(
wmath
::
WPosition
minPos
,
wmath
::
WPosition
maxPos
)
:
WROI
(),
boxId
(
maxBoxId
++
)
boxId
(
maxBoxId
++
),
needUpdate
(
false
)
{
m_minPos
=
minPos
;
m_maxPos
=
maxPos
;
...
...
@@ -122,11 +123,14 @@ WROIBox::WROIBox( wmath::WPosition minPos, wmath::WPosition maxPos ) :
boost
::
shared_ptr
<
WGEViewer
>
viewer
=
ge
->
getViewerByName
(
"main"
);
assert
(
viewer
);
m_pickHandler
=
viewer
->
getPickHandler
();
m_pickHandler
->
getPickSignal
()
->
connect
(
boost
::
bind
(
&
WROIBox
::
updateGFX
,
this
,
_1
)
);
m_pickHandler
->
getPickSignal
()
->
connect
(
boost
::
bind
(
&
WROIBox
::
registerPick
,
this
,
_1
)
);
osg
::
Geometry
*
surfaceGeometry
=
new
osg
::
Geometry
();
m_geode
=
new
osg
::
Geode
;
m_geode
->
setUserData
(
this
);
m_geode
->
setUpdateCallback
(
new
ROIBoxNodeCallback
);
std
::
stringstream
ss
;
ss
<<
"ROIBox"
<<
boxId
;
...
...
@@ -180,16 +184,32 @@ wmath::WPosition WROIBox::getMaxPos() const
return
m_maxPos
;
}
void
WROIBox
::
registerPick
(
std
::
string
text
)
{
boost
::
unique_lock
<
boost
::
shared_mutex
>
slock
;
slock
=
boost
::
unique_lock
<
boost
::
shared_mutex
>
(
m_updateLock
);
infoText
=
text
;
needUpdate
=
true
;
void
WROIBox
::
updateGFX
(
std
::
string
text
)
slock
.
unlock
();
}
void
WROIBox
::
updateGFX
()
{
boost
::
shared_lock
<
boost
::
shared_mutex
>
slock
;
slock
=
boost
::
shared_lock
<
boost
::
shared_mutex
>
(
m_updateLock
);
boost
::
unique_lock
<
boost
::
shared_mutex
>
slock
;
slock
=
boost
::
unique_lock
<
boost
::
shared_mutex
>
(
m_updateLock
);
if
(
!
needUpdate
)
// exit early if we do not need an update
{
slock
.
unlock
();
return
;
}
std
::
stringstream
ss
;
ss
<<
"
\"
ROIBox"
<<
boxId
<<
"
\"
"
;
if
(
t
ext
.
find
(
"Object "
)
!=
std
::
string
::
npos
&&
t
ext
.
find
(
ss
.
str
()
)
!=
std
::
string
::
npos
)
if
(
infoT
ext
.
find
(
"Object "
)
!=
std
::
string
::
npos
&&
infoT
ext
.
find
(
ss
.
str
()
)
!=
std
::
string
::
npos
)
{
wmath
::
WPosition
newPos
(
m_pickHandler
->
getHitPosition
()
);
if
(
m_isPicked
)
...
...
@@ -210,7 +230,7 @@ void WROIBox::updateGFX( std::string text )
m_pickedPosition
=
newPos
;
m_isPicked
=
true
;
}
if
(
m_isPicked
&&
t
ext
.
find
(
"unpick"
)
!=
std
::
string
::
npos
)
if
(
m_isPicked
&&
infoT
ext
.
find
(
"unpick"
)
!=
std
::
string
::
npos
)
{
osg
::
Vec4Array
*
colors
=
new
osg
::
Vec4Array
;
colors
->
push_back
(
osg
::
Vec4
(
0.
f
,
0.
f
,
1.
f
,
0.5
f
)
);
...
...
src/graphicsEngine/WROIBox.h
View file @
e37a6943
...
...
@@ -37,7 +37,7 @@
/**
* A box representing a region of interest.
*/
class
WROIBox
:
public
WROI
class
WROIBox
:
public
WROI
,
public
osg
::
Referenced
{
public:
/**
...
...
@@ -68,11 +68,44 @@ private:
wmath
::
WPosition
m_pickedPosition
;
//!< Caches the old picked position to a allow for cmoparison
boost
::
shared_mutex
m_updateLock
;
//!< Lock to prevent concurrent threads trying to update the osg node
std
::
string
infoText
;
//!< The info text coming from the last pick.
bool
needUpdate
;
//!< Indicates whether the grafics need update due to changed text.
/**
*
updates the graph
ic
s
* \param text
text
info from pick
*
note that there was a p
ic
k
* \param text info from pick
*/
virtual
void
updateGFX
(
std
::
string
text
);
void
registerPick
(
std
::
string
text
);
/**
* updates the graphics
*/
void
updateGFX
();
/**
* Node callback to handle updates properly
*/
class
ROIBoxNodeCallback
:
public
osg
::
NodeCallback
{
public:
// NOLINT
/**
* operator ()
*
* \param node the osg node
* \param nv the node visitor
*/
virtual
void
operator
()(
osg
::
Node
*
node
,
osg
::
NodeVisitor
*
nv
)
{
osg
::
ref_ptr
<
WROIBox
>
module
=
static_cast
<
WROIBox
*
>
(
node
->
getUserData
()
);
if
(
module
)
{
module
->
updateGFX
();
}
traverse
(
node
,
nv
);
}
};
};
#endif // WROIBOX_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