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
50538b83
Commit
50538b83
authored
Mar 18, 2010
by
Mathias Goldau
Browse files
[ADD] Optional Input for selective coloring to the TriangleMesh vertices
parent
a55f2602
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
215 additions
and
14 deletions
+215
-14
src/common/datastructures/CMakeLists.txt
src/common/datastructures/CMakeLists.txt
+1
-0
src/common/datastructures/WColoredVertices.cpp
src/common/datastructures/WColoredVertices.cpp
+54
-0
src/common/datastructures/WColoredVertices.h
src/common/datastructures/WColoredVertices.h
+119
-0
src/modules/triangleMeshRenderer/WMTriangleMeshRenderer.cpp
src/modules/triangleMeshRenderer/WMTriangleMeshRenderer.cpp
+38
-13
src/modules/triangleMeshRenderer/WMTriangleMeshRenderer.h
src/modules/triangleMeshRenderer/WMTriangleMeshRenderer.h
+3
-1
No files found.
src/common/datastructures/CMakeLists.txt
View file @
50538b83
...
...
@@ -4,5 +4,6 @@ FILE( GLOB COMMON_DATASTRUCTURES_SRC "*.cpp" "*.h" )
IF
(
OW_COMPILE_TESTS
)
CXXTEST_ADD_TESTS_FROM_LIST
(
"
${
COMMON_DATASTRUCTURES_SRC
}
"
"common"
# no libs for linking required
"WColoredVertices.cpp"
# is just an container, no logic to test
)
ENDIF
(
OW_COMPILE_TESTS
)
src/common/datastructures/WColoredVertices.cpp
0 → 100644
View file @
50538b83
//---------------------------------------------------------------------------
//
// 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 <map>
#include <boost/shared_ptr.hpp>
#include "WColoredVertices.h"
// init _static_ member variable and provide a linker reference to it
boost
::
shared_ptr
<
WPrototyped
>
WColoredVertices
::
m_prototype
=
boost
::
shared_ptr
<
WPrototyped
>
();
boost
::
shared_ptr
<
WPrototyped
>
WColoredVertices
::
getPrototype
()
{
if
(
!
m_prototype
)
{
m_prototype
=
boost
::
shared_ptr
<
WPrototyped
>
(
new
WColoredVertices
()
);
}
return
m_prototype
;
}
WColoredVertices
::
WColoredVertices
()
{
}
WColoredVertices
::
WColoredVertices
(
const
std
::
map
<
size_t
,
WColor
>&
data
)
:
m_data
(
data
)
{
}
WColoredVertices
::~
WColoredVertices
()
{
}
src/common/datastructures/WColoredVertices.h
0 → 100644
View file @
50538b83
//---------------------------------------------------------------------------
//
// 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 WCOLOREDVERTICES_H
#define WCOLOREDVERTICES_H
#include <map>
#include <string>
#include "../WTransferable.h"
#include "../WColor.h"
/**
* Represents a std::map where for each vertex ID a color is stored.
*/
class
WColoredVertices
:
public
WTransferable
{
public:
/**
* Default constructor.
*/
WColoredVertices
();
/**
* Initialize this with the given map.
*
* \param data The map
*/
explicit
WColoredVertices
(
const
std
::
map
<
size_t
,
WColor
>&
data
);
/**
* Cleans up this instance.
*/
virtual
~
WColoredVertices
();
/**
* Gets the name of this prototype.
*
* \return the name.
*/
virtual
const
std
::
string
getName
()
const
;
/**
* Gets the description for this prototype.
*
* \return the description
*/
virtual
const
std
::
string
getDescription
()
const
;
/**
* Returns a prototype instantiated with the true type of the deriving class.
*
* \return the prototype.
*/
static
boost
::
shared_ptr
<
WPrototyped
>
getPrototype
();
/**
* Reference to the data.
*
* \return Reference to the map of ids and colors.
*/
const
std
::
map
<
size_t
,
WColor
>&
getData
()
const
;
/**
* Replace (copies) the internal data with the given one.
*
* \param data The ID-Color map
*/
void
setData
(
const
std
::
map
<
size_t
,
WColor
>&
data
);
protected:
static
boost
::
shared_ptr
<
WPrototyped
>
m_prototype
;
//!< The prototype as singleton.
private:
std
::
map
<
size_t
,
WColor
>
m_data
;
//!< stores the vertex ids and colors
};
inline
const
std
::
string
WColoredVertices
::
getName
()
const
{
return
"WColoredVertices"
;
}
inline
const
std
::
string
WColoredVertices
::
getDescription
()
const
{
return
"Represents a std::map where for each vertex ID a color is stored."
;
}
inline
const
std
::
map
<
size_t
,
WColor
>&
WColoredVertices
::
getData
()
const
{
return
m_data
;
}
inline
void
WColoredVertices
::
setData
(
const
std
::
map
<
size_t
,
WColor
>&
data
)
{
m_data
=
data
;
}
#endif // WCOLOREDVERTICES_H
src/modules/triangleMeshRenderer/WMTriangleMeshRenderer.cpp
View file @
50538b83
...
...
@@ -23,14 +23,15 @@
//---------------------------------------------------------------------------
#include <string>
#include <map>
#include <osg/LightModel>
#include "../../kernel/WKernel.h"
#include "../../common/datastructures/WTriangleMesh.h"
#include "
WMTriangleMeshRenderer
.h"
#include "../../graphicsEngine/WGEUtils.h"
#include "
../../kernel/WKernel
.h"
#include "trianglemeshrenderer.xpm"
#include "WMTriangleMeshRenderer.h"
WMTriangleMeshRenderer
::
WMTriangleMeshRenderer
()
:
WModule
(),
...
...
@@ -68,11 +69,17 @@ const std::string WMTriangleMeshRenderer::getDescription() const
void
WMTriangleMeshRenderer
::
connectors
()
{
m_
i
nput
=
boost
::
shared_ptr
<
WModuleInputData
<
WTriangleMesh
>
>
(
new
WModuleInputData
<
WTriangleMesh
>
(
shared_from_this
(),
"
in
"
,
"The mesh to display"
)
m_
meshI
nput
=
boost
::
shared_ptr
<
WModuleInputData
<
WTriangleMesh
>
>
(
new
WModuleInputData
<
WTriangleMesh
>
(
shared_from_this
(),
"
mesh
"
,
"The mesh to display"
)
);
addConnector
(
m_input
);
addConnector
(
m_meshInput
);
m_colorMapInput
=
boost
::
shared_ptr
<
WModuleInputData
<
WColoredVertices
>
>
(
new
WModuleInputData
<
WColoredVertices
>
(
shared_from_this
(),
"colorMap"
,
"The special colors"
)
);
addConnector
(
m_colorMapInput
);
// call WModules initialization
WModule
::
connectors
();
...
...
@@ -87,7 +94,8 @@ void WMTriangleMeshRenderer::moduleMain()
{
// let the main loop awake if the data changes or the properties changed.
m_moduleState
.
setResetable
(
true
,
true
);
m_moduleState
.
add
(
m_input
->
getDataChangedCondition
()
);
m_moduleState
.
add
(
m_meshInput
->
getDataChangedCondition
()
);
m_moduleState
.
add
(
m_colorMapInput
->
getDataChangedCondition
()
);
// signal ready state
ready
();
...
...
@@ -107,7 +115,7 @@ void WMTriangleMeshRenderer::moduleMain()
break
;
}
// invalid data
boost
::
shared_ptr
<
WTriangleMesh
>
mesh
=
m_
i
nput
->
getData
();
boost
::
shared_ptr
<
WTriangleMesh
>
mesh
=
m_
meshI
nput
->
getData
();
if
(
!
mesh
)
{
debugLog
()
<<
"Invalid Data. Disabling."
;
...
...
@@ -163,18 +171,35 @@ void WMTriangleMeshRenderer::renderMesh( boost::shared_ptr< WTriangleMesh > mesh
// ------------------------------------------------
// colors
osg
::
Vec4Array
*
colors
=
new
osg
::
Vec4Array
;
osg
::
ref_ptr
<
osg
::
Vec4Array
>
colors
=
osg
::
ref_ptr
<
osg
::
Vec4Array
>
(
new
osg
::
Vec4Array
);
boost
::
shared_ptr
<
WColoredVertices
>
colorMap
=
m_colorMapInput
->
getData
();
if
(
!
colorMap
)
{
colors
->
push_back
(
osg
::
Vec4
(
.9
f
,
.9
f
,
0.9
f
,
1.0
f
)
);
surfaceGeometry
->
setColorArray
(
colors
);
surfaceGeometry
->
setColorBinding
(
osg
::
Geometry
::
BIND_OVERALL
);
}
else
{
for
(
size_t
i
=
0
;
i
<
mesh
->
getNumVertices
();
++
i
)
{
colors
->
push_back
(
osg
::
Vec4
(
.9
f
,
.9
f
,
0.9
f
,
1.0
f
)
);
}
for
(
std
::
map
<
size_t
,
WColor
>::
const_iterator
vc
=
colorMap
->
getData
().
begin
();
vc
!=
colorMap
->
getData
().
end
();
++
vc
)
{
colors
->
at
(
vc
->
first
)
=
wge
::
osgColor
(
vc
->
second
);
}
colors
->
push_back
(
osg
::
Vec4
(
.9
f
,
.9
f
,
0.9
f
,
1.0
f
)
);
surfaceGeometry
->
setColor
Array
(
colors
);
surfaceGeometry
->
setColorBinding
(
osg
::
Geometry
::
BIND_OVERALL
);
surfaceGeometry
->
setColorArray
(
colors
);
surfaceGeometry
->
setColor
Binding
(
osg
::
Geometry
::
BIND_PER_VERTEX
);
}
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
);
m_moduleNode
->
insert
(
m_surfaceGeode
);
WKernel
::
getRunningKernel
()
->
getGraphicsEngine
()
->
getScene
()
->
insert
(
m_moduleNode
);
}
...
...
src/modules/triangleMeshRenderer/WMTriangleMeshRenderer.h
View file @
50538b83
...
...
@@ -29,6 +29,7 @@
#include <osg/Geode>
#include "../../common/datastructures/WColoredVertices.h"
#include "../../graphicsEngine/WGEGroupNode.h"
#include "../../kernel/WModule.h"
#include "../../kernel/WModuleInputData.h"
...
...
@@ -113,7 +114,8 @@ private:
/**
* An input connector used to get mehses from other modules. The connection management between connectors must not be handled by the module.
*/
boost
::
shared_ptr
<
WModuleInputData
<
WTriangleMesh
>
>
m_input
;
boost
::
shared_ptr
<
WModuleInputData
<
WTriangleMesh
>
>
m_meshInput
;
boost
::
shared_ptr
<
WModuleInputData
<
WColoredVertices
>
>
m_colorMapInput
;
//!< for each vertex ID in that container a special color is given.
osg
::
ref_ptr
<
WGEGroupNode
>
m_moduleNode
;
//!< Pointer to the modules group node.
...
...
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