Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
OpenWalnut Core
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
44
Issues
44
List
Boards
Labels
Service Desk
Milestones
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
OpenWalnut
OpenWalnut Core
Commits
3be51551
Commit
3be51551
authored
Jan 06, 2010
by
Alexander Wiebel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[ADD
#218
] cann only draw translucent box by now
parent
115bef58
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
425 additions
and
0 deletions
+425
-0
src/kernel/WModuleFactory.cpp
src/kernel/WModuleFactory.cpp
+2
-0
src/modules/prototypeBoxManipulation/WMPrototypeBoxManipulation.cpp
...s/prototypeBoxManipulation/WMPrototypeBoxManipulation.cpp
+269
-0
src/modules/prototypeBoxManipulation/WMPrototypeBoxManipulation.h
...les/prototypeBoxManipulation/WMPrototypeBoxManipulation.h
+154
-0
No files found.
src/kernel/WModuleFactory.cpp
View file @
3be51551
...
...
@@ -41,6 +41,7 @@
#include "../modules/textureList/WMTextureList.h"
#include "../modules/hud/WMHud.h"
#include "../modules/eegView/WMEEGView.h"
#include "../modules/prototypeBoxManipulation/WMPrototypeBoxManipulation.h"
#include "exceptions/WPrototypeUnknown.h"
#include "exceptions/WPrototypeNotUnique.h"
...
...
@@ -81,6 +82,7 @@ void WModuleFactory::load()
m_prototypes
.
insert
(
boost
::
shared_ptr
<
WModule
>
(
new
WMTextureList
()
)
);
m_prototypes
.
insert
(
boost
::
shared_ptr
<
WModule
>
(
new
WMHud
()
)
);
m_prototypes
.
insert
(
boost
::
shared_ptr
<
WModule
>
(
new
WMEEGView
()
)
);
m_prototypes
.
insert
(
boost
::
shared_ptr
<
WModule
>
(
new
WMPrototypeBoxManipulation
()
)
);
lock
.
unlock
();
...
...
src/modules/prototypeBoxManipulation/WMPrototypeBoxManipulation.cpp
0 → 100644
View file @
3be51551
//---------------------------------------------------------------------------
//
// 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 <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <cmath>
#include "WMPrototypeBoxManipulation.h"
#include <osg/Geode>
#include <osg/Geometry>
#include <osg/StateSet>
#include <osg/StateAttribute>
#include <osg/PolygonMode>
#include <osg/LightModel>
#include <osg/LineWidth>
#include <osgDB/WriteFile>
#include "../../math/WVector3D.h"
#include "../../kernel/WKernel.h"
#include "../../graphicsEngine/WShader.h"
#include "../data/WMData.h"
WMPrototypeBoxManipulation
::
WMPrototypeBoxManipulation
()
:
WModule
()
{
// WARNING: initializing connectors inside the constructor will lead to an exception.
// Implement WModule::initializeConnectors instead.
}
WMPrototypeBoxManipulation
::~
WMPrototypeBoxManipulation
()
{
// cleanup
removeConnectors
();
}
boost
::
shared_ptr
<
WModule
>
WMPrototypeBoxManipulation
::
factory
()
const
{
return
boost
::
shared_ptr
<
WModule
>
(
new
WMPrototypeBoxManipulation
()
);
}
const
std
::
string
WMPrototypeBoxManipulation
::
getName
()
const
{
return
"Box Manipulation"
;
}
const
std
::
string
WMPrototypeBoxManipulation
::
getDescription
()
const
{
return
"Just a prtotype for box manipulation"
;
}
void
WMPrototypeBoxManipulation
::
moduleMain
()
{
// use the m_input "data changed" flag
m_moduleState
.
add
(
m_input
->
getDataChangedCondition
()
);
// signal ready state
ready
();
// loop until the module container requests the module to quit
while
(
!
m_shutdownFlag
()
)
{
draw
();
// this waits for m_moduleState to fire. By default, this is only the m_shutdownFlag condition.
// NOTE: you can add your own conditions to m_moduleState using m_moduleState.add( ... )
m_moduleState
.
wait
();
}
}
void
WMPrototypeBoxManipulation
::
connectors
()
{
// initialize connectors
m_input
=
boost
::
shared_ptr
<
WModuleInputData
<
WDataSetSingle
>
>
(
new
WModuleInputData
<
WDataSetSingle
>
(
shared_from_this
(),
"in"
,
"Dummy in."
)
);
// add it to the list of connectors. Please note, that a connector NOT added via addConnector will not work as expected.
addConnector
(
m_input
);
// call WModules initialization
WModule
::
connectors
();
}
void
WMPrototypeBoxManipulation
::
properties
()
{
m_properties
->
addBool
(
"textureChanged"
,
false
,
true
);
}
void
WMPrototypeBoxManipulation
::
slotPropertyChanged
(
std
::
string
propertyName
)
{
if
(
propertyName
==
"active"
)
{
if
(
m_properties
->
getValue
<
bool
>
(
propertyName
)
)
{
m_geode
->
setNodeMask
(
0xFFFFFFFF
);
}
else
{
m_geode
->
setNodeMask
(
0x0
);
}
}
else
{
std
::
cout
<<
propertyName
<<
std
::
endl
;
assert
(
0
&&
"This property name is not supported by this function yet."
);
}
}
void
buildFacesFromPoints
(
osg
::
DrawElementsUInt
*
surfaceElements
)
{
surfaceElements
->
push_back
(
0
);
surfaceElements
->
push_back
(
2
);
surfaceElements
->
push_back
(
3
);
surfaceElements
->
push_back
(
1
);
surfaceElements
->
push_back
(
2
);
surfaceElements
->
push_back
(
6
);
surfaceElements
->
push_back
(
7
);
surfaceElements
->
push_back
(
3
);
surfaceElements
->
push_back
(
6
);
surfaceElements
->
push_back
(
4
);
surfaceElements
->
push_back
(
5
);
surfaceElements
->
push_back
(
7
);
surfaceElements
->
push_back
(
4
);
surfaceElements
->
push_back
(
0
);
surfaceElements
->
push_back
(
1
);
surfaceElements
->
push_back
(
5
);
surfaceElements
->
push_back
(
1
);
surfaceElements
->
push_back
(
3
);
surfaceElements
->
push_back
(
7
);
surfaceElements
->
push_back
(
5
);
surfaceElements
->
push_back
(
0
);
surfaceElements
->
push_back
(
4
);
surfaceElements
->
push_back
(
6
);
surfaceElements
->
push_back
(
2
);
}
void
buildLinesFromPoints
(
osg
::
DrawElementsUInt
*
surfaceElements
)
{
surfaceElements
->
push_back
(
0
);
surfaceElements
->
push_back
(
2
);
surfaceElements
->
push_back
(
2
);
surfaceElements
->
push_back
(
3
);
surfaceElements
->
push_back
(
3
);
surfaceElements
->
push_back
(
1
);
surfaceElements
->
push_back
(
1
);
surfaceElements
->
push_back
(
0
);
surfaceElements
->
push_back
(
6
);
surfaceElements
->
push_back
(
4
);
surfaceElements
->
push_back
(
4
);
surfaceElements
->
push_back
(
5
);
surfaceElements
->
push_back
(
5
);
surfaceElements
->
push_back
(
7
);
surfaceElements
->
push_back
(
7
);
surfaceElements
->
push_back
(
6
);
surfaceElements
->
push_back
(
2
);
surfaceElements
->
push_back
(
6
);
surfaceElements
->
push_back
(
7
);
surfaceElements
->
push_back
(
3
);
surfaceElements
->
push_back
(
4
);
surfaceElements
->
push_back
(
0
);
surfaceElements
->
push_back
(
1
);
surfaceElements
->
push_back
(
5
);
}
void
setVertices
(
osg
::
Vec3Array
*
vertices
)
{
const
double
offset
=
30.
;
vertices
->
push_back
(
osg
::
Vec3
(
30
,
30
,
30
)
);
vertices
->
push_back
(
osg
::
Vec3
(
30
,
30
,
30
+
offset
)
);
vertices
->
push_back
(
osg
::
Vec3
(
30
,
30
+
offset
,
30
)
);
vertices
->
push_back
(
osg
::
Vec3
(
30
,
30
+
offset
,
30
+
offset
)
);
vertices
->
push_back
(
osg
::
Vec3
(
30
+
offset
,
30
,
30
)
);
vertices
->
push_back
(
osg
::
Vec3
(
30
+
offset
,
30
,
30
+
offset
)
);
vertices
->
push_back
(
osg
::
Vec3
(
30
+
offset
,
30
+
offset
,
30
)
);
vertices
->
push_back
(
osg
::
Vec3
(
30
+
offset
,
30
+
offset
,
30
+
offset
)
);
}
void
WMPrototypeBoxManipulation
::
draw
()
{
osg
::
Geometry
*
surfaceGeometry
=
new
osg
::
Geometry
();
m_geode
=
new
osg
::
Geode
;
m_geode
->
setName
(
"Box"
);
osg
::
Vec3Array
*
vertices
=
new
osg
::
Vec3Array
;
setVertices
(
vertices
);
surfaceGeometry
->
setVertexArray
(
vertices
);
osg
::
DrawElementsUInt
*
surfaceElements
;
surfaceElements
=
new
osg
::
DrawElementsUInt
(
osg
::
PrimitiveSet
::
QUADS
,
0
);
buildFacesFromPoints
(
surfaceElements
);
osg
::
DrawElementsUInt
*
lineElements
;
lineElements
=
new
osg
::
DrawElementsUInt
(
osg
::
PrimitiveSet
::
LINES
,
0
);
buildLinesFromPoints
(
lineElements
);
surfaceGeometry
->
addPrimitiveSet
(
surfaceElements
);
surfaceGeometry
->
addPrimitiveSet
(
lineElements
);
m_geode
->
addDrawable
(
surfaceGeometry
);
osg
::
StateSet
*
state
=
m_geode
->
getOrCreateStateSet
();
state
->
setRenderingHint
(
osg
::
StateSet
::
TRANSPARENT_BIN
);
osg
::
LineWidth
*
linewidth
=
new
osg
::
LineWidth
();
linewidth
->
setWidth
(
2.
f
);
state
->
setAttributeAndModes
(
linewidth
,
osg
::
StateAttribute
::
ON
);
// ------------------------------------------------
// colors
osg
::
Vec4Array
*
colors
=
new
osg
::
Vec4Array
;
colors
->
push_back
(
osg
::
Vec4
(
.9
f
,
.9
f
,
0.9
f
,
0.5
f
)
);
surfaceGeometry
->
setColorArray
(
colors
);
surfaceGeometry
->
setColorBinding
(
osg
::
Geometry
::
BIND_OVERALL
);
osg
::
ref_ptr
<
osg
::
LightModel
>
lightModel
=
new
osg
::
LightModel
();
lightModel
->
setTwoSided
(
true
);
state
->
setAttributeAndModes
(
lightModel
.
get
(),
osg
::
StateAttribute
::
ON
);
state
->
setMode
(
GL_BLEND
,
osg
::
StateAttribute
::
ON
);
WKernel
::
getRunningKernel
()
->
getGraphicsEngine
()
->
getScene
()
->
addChild
(
m_geode
);
debugLog
()
<<
"Intial draw "
<<
std
::
endl
;
}
void
WMPrototypeBoxManipulation
::
updateGFX
()
{
boost
::
shared_lock
<
boost
::
shared_mutex
>
slock
;
slock
=
boost
::
shared_lock
<
boost
::
shared_mutex
>
(
m_updateLock
);
slock
.
unlock
();
}
src/modules/prototypeBoxManipulation/WMPrototypeBoxManipulation.h
0 → 100644
View file @
3be51551
//---------------------------------------------------------------------------
//
// 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 WMPROTOTYPEBOXMANIPULATION_H
#define WMPROTOTYPEBOXMANIPULATION_H
#include <map>
#include <string>
#include <vector>
#include <osg/Node>
#include <osg/Geode>
#include <osg/Uniform>
#include "../../kernel/WModule.h"
#include "../../kernel/WModuleInputData.h"
/**
* Prototype module
*/
class
WMPrototypeBoxManipulation
:
public
WModule
{
public:
/**
* Standard constructor.
*/
WMPrototypeBoxManipulation
();
/**
* Destructor.
*/
~
WMPrototypeBoxManipulation
();
/**
* Gives back the name of this module.
* \return the module's name.
*/
virtual
const
std
::
string
getName
()
const
;
/**
* Gives back a description of this module.
* \return description of module.
*/
virtual
const
std
::
string
getDescription
()
const
;
/**
* Determine what to do if a property was changed.
* \param propertyName Name of the property.
*/
void
slotPropertyChanged
(
std
::
string
propertyName
);
/**
* Due to the prototype design pattern used to build modules, this method returns a new instance of this method. NOTE: it
* should never be initialized or modified in some other way. A simple new instance is required.
*
* \return the prototype used to create every module in OpenWalnut.
*/
virtual
boost
::
shared_ptr
<
WModule
>
factory
()
const
;
/**
* updates the graphics
*/
void
updateGFX
();
protected:
/**
* Entry point after loading the module. Runs in separate thread.
*/
virtual
void
moduleMain
();
/**
* Initialize the connectors this module is using.
*/
virtual
void
connectors
();
/**
* Initialize the properties for this module.
*/
virtual
void
properties
();
private:
/**
* draw initial graphics
*/
void
draw
();
boost
::
shared_mutex
m_updateLock
;
//!< Lock to prevent concurrent threads trying to update the osg node
osg
::
Geode
*
m_geode
;
//!< Pointer to geode. We need it to be able to update it when callback is invoked.
boost
::
shared_ptr
<
WModuleInputData
<
WDataSetSingle
>
>
m_input
;
//!< Input connector required by this module.
};
/**
* Adapter object for realizing callbacks of the node representing the box in the osg
*/
class
BoxNodeCallback
:
public
osg
::
NodeCallback
{
public:
/**
* Constructor of the callback adapter.
* \param module A function of this module will be called
*/
explicit
BoxNodeCallback
(
boost
::
shared_ptr
<
WMPrototypeBoxManipulation
>
module
);
/**
* Function that is called by the osg and that call the function in the module.
* \param node The node we are called.
* \param nv the visitor calling us.
*/
virtual
void
operator
()(
osg
::
Node
*
node
,
osg
::
NodeVisitor
*
nv
);
private:
boost
::
shared_ptr
<
WMPrototypeBoxManipulation
>
m_module
;
//!< Pointer to the module to which the function that is called belongs to.
};
inline
BoxNodeCallback
::
BoxNodeCallback
(
boost
::
shared_ptr
<
WMPrototypeBoxManipulation
>
module
)
:
m_module
(
module
)
{
}
inline
void
BoxNodeCallback
::
operator
()(
osg
::
Node
*
node
,
osg
::
NodeVisitor
*
nv
)
{
if
(
m_module
)
{
m_module
->
updateGFX
();
}
traverse
(
node
,
nv
);
}
#endif // WMPROTOTYPEBOXMANIPULATION_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