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
f27506d7
Commit
f27506d7
authored
Aug 05, 2010
by
schurade
Browse files
[ADD] module that draws planes of arbitrary location and orientation
parent
df2d07e0
Changes
10
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
1230 additions
and
0 deletions
+1230
-0
src/graphicsEngine/WROI.cpp
src/graphicsEngine/WROI.cpp
+9
-0
src/graphicsEngine/WROI.h
src/graphicsEngine/WROI.h
+10
-0
src/graphicsEngine/WROISphere.cpp
src/graphicsEngine/WROISphere.cpp
+209
-0
src/graphicsEngine/WROISphere.h
src/graphicsEngine/WROISphere.h
+181
-0
src/modules/CMakeLists.txt
src/modules/CMakeLists.txt
+1
-0
src/modules/arbitraryPlane/CMakeLists.txt
src/modules/arbitraryPlane/CMakeLists.txt
+42
-0
src/modules/arbitraryPlane/WMArbitraryPlane.cpp
src/modules/arbitraryPlane/WMArbitraryPlane.cpp
+393
-0
src/modules/arbitraryPlane/WMArbitraryPlane.h
src/modules/arbitraryPlane/WMArbitraryPlane.h
+250
-0
src/modules/arbitraryPlane/shaders/WMArbitraryPlane-fragment.glsl
...les/arbitraryPlane/shaders/WMArbitraryPlane-fragment.glsl
+114
-0
src/modules/arbitraryPlane/shaders/WMArbitraryPlane-vertex.glsl
...dules/arbitraryPlane/shaders/WMArbitraryPlane-vertex.glsl
+21
-0
No files found.
src/graphicsEngine/WROI.cpp
View file @
f27506d7
...
...
@@ -69,3 +69,12 @@ bool WROI::isModified()
return
tmp
;
}
void
WROI
::
hide
()
{
setNodeMask
(
0x0
);
}
void
WROI
::
unhide
()
{
setNodeMask
(
0xFFFFFFFF
);
}
src/graphicsEngine/WROI.h
View file @
f27506d7
...
...
@@ -84,6 +84,16 @@ public:
*/
void
setActive
(
bool
active
);
/**
* hides the roi in the scene
*/
void
hide
();
/**
* unhides the roi in the scene
*/
void
unhide
();
/**
* Getter for modified flag
*/
...
...
src/graphicsEngine/WROISphere.cpp
0 → 100644
View file @
f27506d7
//---------------------------------------------------------------------------
//
// Project: OpenWalnut ( http://www.openwalnut.org )
//
// Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
// For more information see http://www.openwalnut.org/copying
//
// This file is part of OpenWalnut.
//
// OpenWalnut is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// OpenWalnut is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
//
//---------------------------------------------------------------------------
#include <string>
#include <utility>
#include <osg/LightModel>
#include "WROISphere.h"
#include "WGraphicsEngine.h"
#include "WGEUtils.h"
size_t
WROISphere
::
maxSphereId
=
0
;
WROISphere
::
WROISphere
(
wmath
::
WPosition
position
,
float
radius
)
:
WROI
(),
sphereId
(
maxSphereId
++
),
m_position
(
position
),
m_originalPosition
(
position
),
m_radius
(
radius
),
m_lockX
(
false
),
m_lockY
(
false
),
m_lockZ
(
false
),
m_pickNormal
(
wmath
::
WVector3D
()
),
m_oldPixelPosition
(
std
::
make_pair
(
0
,
0
)
),
m_color
(
osg
::
Vec4
(
0.
f
,
1.
f
,
1.
f
,
0.4
f
)
),
m_notColor
(
osg
::
Vec4
(
1.0
f
,
0.0
f
,
0.0
f
,
0.4
f
)
)
{
boost
::
shared_ptr
<
WGraphicsEngine
>
ge
=
WGraphicsEngine
::
getGraphicsEngine
();
assert
(
ge
);
boost
::
shared_ptr
<
WGEViewer
>
viewer
=
ge
->
getViewerByName
(
"main"
);
assert
(
viewer
);
m_viewer
=
viewer
;
m_pickHandler
=
m_viewer
->
getPickHandler
();
m_pickHandler
->
getPickSignal
()
->
connect
(
boost
::
bind
(
&
WROISphere
::
registerRedrawRequest
,
this
,
_1
)
);
redrawSphere
();
//**********************************************************
m_isModified
=
true
;
m_isNot
=
false
;
assert
(
WGraphicsEngine
::
getGraphicsEngine
()
);
WGraphicsEngine
::
getGraphicsEngine
()
->
getScene
()
->
addChild
(
this
);
setUserData
(
this
);
setUpdateCallback
(
osg
::
ref_ptr
<
ROISphereNodeCallback
>
(
new
ROISphereNodeCallback
)
);
}
void
WROISphere
::
redrawSphere
()
{
removeDrawables
(
0
);
osg
::
ShapeDrawable
*
shape
=
new
osg
::
ShapeDrawable
(
new
osg
::
Sphere
(
osg
::
Vec3
(
m_position
[
0
],
m_position
[
1
],
m_position
[
2
]
),
m_radius
)
);
std
::
stringstream
ss
;
ss
<<
"ROISphere"
<<
sphereId
;
setName
(
ss
.
str
()
);
shape
->
setName
(
ss
.
str
()
);
addDrawable
(
shape
);
}
WROISphere
::~
WROISphere
()
{
// std::cout << "destructor called" << std::endl;
// std::cout << "ref count geode: " << m_geode->referenceCount() << std::endl;
//
// WGraphicsEngine::getGraphicsEngine()->getScene()->remove( m_geode );
}
wmath
::
WPosition
WROISphere
::
getPosition
()
const
{
return
m_position
;
}
void
WROISphere
::
setPosition
(
wmath
::
WPosition
position
)
{
m_position
=
position
;
m_originalPosition
=
position
;
m_isModified
=
true
;
}
void
WROISphere
::
registerRedrawRequest
(
WPickInfo
pickInfo
)
{
m_pickInfo
=
pickInfo
;
}
void
WROISphere
::
updateGFX
()
{
std
::
stringstream
ss
;
ss
<<
"ROISphere"
<<
sphereId
<<
""
;
if
(
m_pickInfo
.
getName
()
==
ss
.
str
()
)
{
std
::
pair
<
float
,
float
>
newPixelPos
(
m_pickInfo
.
getPickPixelPosition
()
);
if
(
m_isPicked
)
{
osg
::
Vec3
in
(
newPixelPos
.
first
,
newPixelPos
.
second
,
0.0
);
osg
::
Vec3
world
=
wge
::
unprojectFromScreen
(
in
,
m_viewer
->
getCamera
()
);
wmath
::
WPosition
newPixelWorldPos
(
world
[
0
],
world
[
1
],
world
[
2
]
);
wmath
::
WPosition
oldPixelWorldPos
;
if
(
m_oldPixelPosition
.
first
==
0
&&
m_oldPixelPosition
.
second
==
0
)
{
oldPixelWorldPos
=
newPixelWorldPos
;
}
else
{
osg
::
Vec3
in
(
m_oldPixelPosition
.
first
,
m_oldPixelPosition
.
second
,
0.0
);
osg
::
Vec3
world
=
wge
::
unprojectFromScreen
(
in
,
m_viewer
->
getCamera
()
);
oldPixelWorldPos
=
wmath
::
WPosition
(
world
[
0
],
world
[
1
],
world
[
2
]
);
}
wmath
::
WVector3D
moveVec
=
newPixelWorldPos
-
oldPixelWorldPos
;
osg
::
ref_ptr
<
osg
::
Vec3Array
>
vertices
=
osg
::
ref_ptr
<
osg
::
Vec3Array
>
(
new
osg
::
Vec3Array
);
// move sphere
if
(
m_pickInfo
.
getModifierKey
()
==
WPickInfo
::
NONE
)
{
moveSphere
(
moveVec
);
}
}
m_oldPixelPosition
=
newPixelPos
;
m_isModified
=
true
;
m_isPicked
=
true
;
m_signalIsModified
();
}
if
(
m_isPicked
&&
m_pickInfo
.
getName
()
==
"unpick"
)
{
// Perform all actions necessary for finishing a pick
m_pickNormal
=
wmath
::
WVector3D
();
m_isPicked
=
false
;
}
if
(
isModified
()
)
{
redrawSphere
();
}
}
void
WROISphere
::
moveSphere
(
wmath
::
WVector3D
offset
)
{
m_position
+=
offset
;
if
(
m_lockX
)
{
m_position
[
0
]
=
m_originalPosition
[
0
];
}
if
(
m_lockY
)
{
m_position
[
1
]
=
m_originalPosition
[
1
];
}
if
(
m_lockZ
)
{
m_position
[
2
]
=
m_originalPosition
[
2
];
}
}
void
WROISphere
::
setLockX
(
bool
value
)
{
m_lockX
=
value
;
}
void
WROISphere
::
setLockY
(
bool
value
)
{
m_lockY
=
value
;
}
void
WROISphere
::
setLockZ
(
bool
value
)
{
m_lockZ
=
value
;
}
void
WROISphere
::
setColor
(
osg
::
Vec4
color
)
{
m_color
=
color
;
}
void
WROISphere
::
setNotColor
(
osg
::
Vec4
color
)
{
m_notColor
=
color
;
}
src/graphicsEngine/WROISphere.h
0 → 100644
View file @
f27506d7
//---------------------------------------------------------------------------
//
// Project: OpenWalnut ( http://www.openwalnut.org )
//
// Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
// For more information see http://www.openwalnut.org/copying
//
// This file is part of OpenWalnut.
//
// OpenWalnut is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// OpenWalnut is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
//
//---------------------------------------------------------------------------
#ifndef WROISPHERE_H
#define WROISPHERE_H
#include <string>
#include <utility>
#include <boost/thread.hpp>
#include "../common/math/WPosition.h"
#include "WPickHandler.h"
#include "WGEViewer.h"
#include "WROI.h"
/**
* A box representing a region of interest.
*/
class
WROISphere
:
public
WROI
{
public:
/**
* Yields box with desired extremal points minPos and maxPos
* \param position position of the center of the sphere
* \param radius radius of the sphere
*/
WROISphere
(
wmath
::
WPosition
position
,
float
radius
=
5.0
);
/**
* standard destructor
*/
virtual
~
WROISphere
();
/**
* getter
* \return position
*/
wmath
::
WPosition
getPosition
()
const
;
/**
* setter
* \param position
*/
void
setPosition
(
wmath
::
WPosition
position
);
/**
* setter
* \param color
*/
void
setColor
(
osg
::
Vec4
color
);
/**
* setter
* \param color
*/
void
setNotColor
(
osg
::
Vec4
color
);
/**
* removes the old drawable from the osg geode and adds a new one at the current position and size
*/
void
redrawSphere
();
/**
* sets the flag that allows or disallows movement along the x axis
*
* \param value the flag
*/
void
setLockX
(
bool
value
=
true
);
/**
* sets the flag that allows or disallows movement along the y axis
*
* \param value the flag
*/
void
setLockY
(
bool
value
=
true
);
/**
* sets the flag that allows or disallows movement along the z axis
*
* \param value the flag
*/
void
setLockZ
(
bool
value
=
true
);
/**
* move the sphere with a given offset
*
* \param offset the distance to move
*/
void
moveSphere
(
wmath
::
WVector3D
offset
);
protected:
private:
static
size_t
maxSphereId
;
//!< Current maximum boxId over all spheres.
size_t
sphereId
;
//!< Id of the current sphere.
wmath
::
WPosition
m_position
;
//!< The position of the sphere
wmath
::
WPosition
m_originalPosition
;
//!< The position of the sphere when created, used for locking
float
m_radius
;
//!< The radius of the sphere
bool
m_lockX
;
//!< if true disallows changing of the X component of the position
bool
m_lockY
;
//!< if true disallows changing of the Y component of the position
bool
m_lockZ
;
//!< if true disallows changing of the Z component of the position
bool
m_isPicked
;
//!< Indicates whether the box is currently picked or not.
wmath
::
WPosition
m_pickedPosition
;
//!< Caches the old picked position to a allow for comparison
wmath
::
WVector3D
m_pickNormal
;
//!< Store the normal that occured when the pick action was started.
std
::
pair
<
float
,
float
>
m_oldPixelPosition
;
//!< Caches the old picked position to a allow for cmoparison
WPickInfo
m_pickInfo
;
//!< Stores the pick information for potential redraw
boost
::
shared_ptr
<
WGEViewer
>
m_viewer
;
//!< makes viewer available all over this class.
osg
::
Vec4
m_color
;
//!< the color of the box
osg
::
Vec4
m_notColor
;
//!< the color of the box when negated
/**
* note that there was a pick
* \param pickInfo info from pick
*/
void
registerRedrawRequest
(
WPickInfo
pickInfo
);
/**
* updates the graphics
*/
virtual
void
updateGFX
();
/**
* Node callback to handle updates properly
*/
class
ROISphereNodeCallback
:
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
<
WROISphere
>
module
=
static_cast
<
WROISphere
*
>
(
node
->
getUserData
()
);
if
(
module
)
{
module
->
updateGFX
();
}
traverse
(
node
,
nv
);
}
};
};
#endif // WROISPHERE_H
src/modules/CMakeLists.txt
View file @
f27506d7
ADD_SUBDIRECTORY
(
applyMask
)
ADD_SUBDIRECTORY
(
arbitraryPlane
)
ADD_SUBDIRECTORY
(
arbitraryRois
)
ADD_SUBDIRECTORY
(
atlasSurfaces
)
ADD_SUBDIRECTORY
(
boundingBox
)
...
...
src/modules/arbitraryPlane/CMakeLists.txt
0 → 100644
View file @
f27506d7
FILE
(
GLOB_RECURSE MODULES_SRC
"*.cpp"
"*.h"
)
# Grab module name and setup target directories
GET_FILENAME_COMPONENT
(
MODULE_NAME
${
CMAKE_CURRENT_SOURCE_DIR
}
NAME
)
SET
(
MODULE_TARGET_DIR
${
CMAKE_LIBRARY_OUTPUT_DIRECTORY
}
/modules/
${
MODULE_NAME
}
)
SET
(
CMAKE_LIBRARY_OUTPUT_DIRECTORY
${
MODULE_TARGET_DIR
}
)
SET
(
CMAKE_RUNTIME_OUTPUT_DIRECTORY
${
MODULE_TARGET_DIR
}
)
SET
(
MODULE_DIRNAME
${
MODULE_NAME
}
)
SET
(
MODULE_NAME
"OWmodule_
${
MODULE_NAME
}
"
)
# prefix all module names with "OWmodule_" to separate them from other libs
# Build module lib
ADD_LIBRARY
(
${
MODULE_NAME
}
SHARED
${
MODULES_SRC
}
)
TARGET_LINK_LIBRARIES
(
${
MODULE_NAME
}
OWkernel teem
)
# Copy local shaders to module target directory
IF
(
OW_COPY_SHADERS AND EXISTS
${
CMAKE_CURRENT_SOURCE_DIR
}
/shaders
)
# copy shaders only if the user wants it
ADD_CUSTOM_TARGET
(
${
MODULE_NAME
}
_CopyShaders
COMMAND
${
CMAKE_COMMAND
}
-E copy_directory
${
CMAKE_CURRENT_SOURCE_DIR
}
/shaders
${
MODULE_TARGET_DIR
}
/shaders/
COMMENT
"Copy shaders of
${
MODULE_NAME
}
"
)
ADD_DEPENDENCIES
(
${
MODULE_NAME
}
${
MODULE_NAME
}
_CopyShaders
)
ENDIF
()
# Build unit tests
IF
(
OW_COMPILE_TESTS
)
# This ensures that the test is copied to the module directory
SET
(
CMAKE_RUNTIME_OUTPUT_DIRECTORY
${
MODULE_TARGET_DIR
}
)
CXXTEST_ADD_TESTS_FROM_LIST
(
"
${
MODULES_SRC
}
"
"OWkernel;
${
MODULE_NAME
}
"
)
# Copy fixtures if they exist
IF
(
EXISTS
${
CMAKE_CURRENT_SOURCE_DIR
}
/test/fixtures
)
ADD_CUSTOM_TARGET
(
${
MODULE_NAME
}
_CopyFixtures
# as the "test" target runs in CMakes temporary build dir, the fixtures need to be placed there too.
COMMAND
${
CMAKE_COMMAND
}
-E copy_directory
${
CMAKE_CURRENT_SOURCE_DIR
}
/test/fixtures
${
CMAKE_BINARY_DIR
}
/modules/
${
MODULE_DIRNAME
}
/fixtures/
COMMENT
"Copy fixtures of
${
MODULE_NAME
}
"
)
ADD_DEPENDENCIES
(
${
MODULE_NAME
}
${
MODULE_NAME
}
_CopyFixtures
)
ENDIF
(
EXISTS
${
CMAKE_CURRENT_SOURCE_DIR
}
/test/fixtures
)
ENDIF
(
OW_COMPILE_TESTS
)
src/modules/arbitraryPlane/WMArbitraryPlane.cpp
0 → 100644
View file @
f27506d7
//---------------------------------------------------------------------------
//
// Project: OpenWalnut ( http://www.openwalnut.org )
//
// Copyright 2009 OpenWalnut Community, BSV-Leipzig and CNCF-CBS
// For more information see http://www.openwalnut.org/copying
//
// This file is part of OpenWalnut.
//
// OpenWalnut is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// OpenWalnut is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
//
//---------------------------------------------------------------------------
#include <string>
#include <vector>
#include "../../kernel/WKernel.h"
#include "../../dataHandler/WDataSet.h"
#include "../../dataHandler/WDataHandler.h"
#include "../../dataHandler/WDataSetSingle.h"
#include "../../dataHandler/WDataSetScalar.h"
#include "../../dataHandler/WDataTexture3D.h"
#include "../../dataHandler/WGridRegular3D.h"
#include "../../dataHandler/WSubject.h"
#include "../../dataHandler/WValueSet.h"
#include "../../graphicsEngine/WShader.h"
#include "../../graphicsEngine/WGEUtils.h"
#include "WMArbitraryPlane.h"
// This line is needed by the module loader to actually find your module. Do not remove. Do NOT add a ";" here.
W_LOADABLE_MODULE
(
WMArbitraryPlane
)
WMArbitraryPlane
::
WMArbitraryPlane
()
:
WModule
(),
m_dirty
(
false
),
m_textureChanged
(
true
)
{
// initialize members
}
WMArbitraryPlane
::~
WMArbitraryPlane
()
{
// Cleanup!
}
boost
::
shared_ptr
<
WModule
>
WMArbitraryPlane
::
factory
()
const
{
// See "src/modules/template/" for an extensively documented example.
return
boost
::
shared_ptr
<
WModule
>
(
new
WMArbitraryPlane
()
);
}
const
std
::
string
WMArbitraryPlane
::
getName
()
const
{
// Specify your module name here. This name must be UNIQUE!
return
"ArbitraryPlane"
;
}
const
std
::
string
WMArbitraryPlane
::
getDescription
()
const
{
return
"Modul draws an arbitrarily moveable plane through the brain. That rhymes."
;
}
void
WMArbitraryPlane
::
connectors
()
{
// Put the code for your connectors here. See "src/modules/template/" for an extensively documented example.
// call WModules initialization
WModule
::
connectors
();
}
void
WMArbitraryPlane
::
properties
()
{
// Initialize the properties
m_propCondition
=
boost
::
shared_ptr
<
WCondition
>
(
new
WCondition
()
);
m_showComplete
=
m_properties
->
addProperty
(
"show complete"
,
"Slice should be drawn complete even if the texture value is zero."
,
false
,
m_propCondition
);
m_showManipulators
=
m_properties
->
addProperty
(
"show manipulators"
,
"Hide/Show manipulators."
,
true
,
m_propCondition
);
}
void
WMArbitraryPlane
::
moduleMain
()
{
m_shader
=
osg
::
ref_ptr
<
WShader
>
(
new
WShader
(
"WMArbitraryPlane"
,
m_localPath
)
);
initPlane
();
updatePlane
();
osg
::
StateSet
*
rootState
=
m_rootNode
->
getOrCreateStateSet
();
initUniforms
(
rootState
);
updateTextures
();
m_shader
->
apply
(
m_rootNode
);
boost
::
signals2
::
connection
con
=
WDataHandler
::
getDefaultSubject
()
->
getChangeCondition
()
->
subscribeSignal
(
boost
::
bind
(
&
WMArbitraryPlane
::
notifyTextureChange
,
this
)
);
ready
();
m_moduleState
.
setResetable
(
true
,
true
);
m_moduleState
.
add
(
m_propCondition
);
while
(
!
m_shutdownFlag
()
)
{
m_moduleState
.
wait
();
if
(
m_showComplete
->
changed
()
)
{
m_dirty
=
true
;
}
if
(
m_showManipulators
->
changed
()
)
{
if
(
m_showManipulators
->
get
(
true
)
)
{
m_s0
->
unhide
();
m_s1
->
unhide
();
m_s2
->
unhide
();
}
else
{
m_s0
->
hide
();
m_s1
->
hide
();
m_s2
->
hide
();
}
}
if
(
m_shutdownFlag
()
)
{