Commit 3c2dc3c9 authored by cornimueller's avatar cornimueller
Browse files

[ADD] Perform transformation before triangulate the head surface to get a better looking mesh.

parent 07623160
......@@ -95,7 +95,7 @@ osg::ref_ptr< osg::Vec3Array > wge::generateCuboidQuadNormals( const std::vector
return vertices;
}
WTriangleMesh wge::triangulate( const std::vector< wmath::WPosition >& points )
WTriangleMesh wge::triangulate( const std::vector< wmath::WPosition >& points, double transformationFactor )
{
WTriangleMesh mesh;
mesh.setVertices( points );
......@@ -104,6 +104,25 @@ WTriangleMesh wge::triangulate( const std::vector< wmath::WPosition >& points )
{
osg::ref_ptr< osg::Vec3Array > osgPoints = wge::osgVec3Array( points );
if( transformationFactor != 0.0 )
{
// Transform the points as described in the Doxygen description of
// this function.
osg::Vec3 centroid;
for( std::size_t pointID = 0; pointID < osgPoints->size(); ++pointID )
{
centroid += (*osgPoints)[pointID];
}
centroid /= osgPoints->size();
for( std::size_t pointID = 0; pointID < osgPoints->size(); ++pointID )
{
const double factor = ( (*osgPoints)[pointID].z() - centroid.z() ) * transformationFactor + 1.0;
(*osgPoints)[pointID].x() = ( (*osgPoints)[pointID].x() - centroid.x() ) * factor + centroid.x();
(*osgPoints)[pointID].y() = ( (*osgPoints)[pointID].y() - centroid.y() ) * factor + centroid.y();
}
}
// The osg triangulator sorts the points and returns the triangles with
// the indizes of the sorted points. Since we don't want to change the
// sequence of the points, we have to save the original index of each
......
......@@ -105,12 +105,25 @@ namespace wge
osg::ref_ptr< osg::Vec3Array > generateCuboidQuadNormals( const std::vector< wmath::WPosition >& corners );
/**
* Calculate the Delaunay Triangulatation of the given points.
* Calculate the Delaunay Triangulation of the given points.
*
* \param points vector of the points to triangulate
* If the parameter transformationFactor is not zero, the points will be
* transformed to calcule the triangles to get a better triangulation, but
* the returned mesh will consist of the original points.
* Every point which lies above the centroid of all points will be put away
* from this centroid by transformationFactor * height above the centroid.
* Any point below the centroid will be drawn to the centroid because its
* height is negative. This effect is inverted with a negative
* transformationFactor.
* This transformation is used to calculate the head surface between several
* electrodes, were a transformationFactor of -0.005 is reasonable.
*
* \param points vector of the points to triangulate
* \param transformationFactor magnitude of the transformation before the
* triangulation
* \return triangulation as WTriangleMesh
*/
WTriangleMesh triangulate( const std::vector< wmath::WPosition >& points );
WTriangleMesh triangulate( const std::vector< wmath::WPosition >& points, double transformationFactor = 0.0 );
}
#endif // WGEGEOMETRYUTILS_H
......@@ -608,7 +608,7 @@ osg::ref_ptr< osg::Node > WMEEGView::drawHeadSurface()
const std::size_t nbPositions = positions.size();
WTriangleMesh mesh = wge::triangulate( positions );
WTriangleMesh mesh = wge::triangulate( positions, -0.005 );
osg::ref_ptr< osg::Geometry > geometry = wge::convertToOsgGeometry( &mesh, true );
osg::Vec4Array* colors = new osg::Vec4Array;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment