Commit 280bac9d authored by Alexander Wiebel's avatar Alexander Wiebel
Browse files

[MERGE]

parents d5683ac0 38e2994f
This diff is collapsed.
......@@ -2,7 +2,7 @@
//
// Project: OpenWalnut ( http://www.openwalnut.org )
//
// Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
// Copyright 2013 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
// For more information see http://www.openwalnut.org/copying
//
// This file is part of OpenWalnut.
......@@ -27,9 +27,13 @@
#include <algorithm>
#include <cassert>
#include <iomanip>
#include <sstream>
#include <string>
#include <vector>
#include <boost/shared_ptr.hpp>
#include "../exceptions/WOutOfBounds.h"
/**
......@@ -39,7 +43,7 @@
* \note There exists also a WWriter and WReader for storing/reading the matrix in VTK file format.
*/
template< typename T >
class WMatrixSymImpl
class WMatrixSym
{
friend class WMatrixSymTest;
public:
......@@ -48,17 +52,22 @@ public:
*/
typedef T value_type;
/**
* Shorthand for shared pointers.
*/
typedef boost::shared_ptr< WMatrixSym < T > > SPtr;
/**
* Generates new symmetric matrix.
*
* \param n number of rows and cols
*/
explicit WMatrixSymImpl( size_t n );
explicit WMatrixSym( size_t n );
/**
* Default constructor leaving all empty.
*/
WMatrixSymImpl();
WMatrixSym();
/**
* Element acces operator as if the elements where stored as a normal matrix.
......@@ -71,6 +80,17 @@ public:
* \return reference to the (i,j) element of the table
*/
T& operator()( size_t i, size_t j ) throw( WOutOfBounds );
/**
* Const version of the element access.
*
* \warning Acessing elements of the main diagonal is forbidden!
*
* \param i The i'th row
* \param j The j'th column
*
* \return Const reference to the (i,j) element of the table
*/
const T& operator()( size_t i, size_t j ) const throw( WOutOfBounds );
/**
......@@ -120,20 +140,20 @@ private:
};
template< typename T >
inline WMatrixSymImpl< T >::WMatrixSymImpl( size_t n )
inline WMatrixSym< T >::WMatrixSym( size_t n )
: m_data( ( n * ( n - 1 ) ) / 2, 0.0 ),
m_n( n )
{
}
template< typename T >
inline WMatrixSymImpl< T >::WMatrixSymImpl()
inline WMatrixSym< T >::WMatrixSym()
: m_n( 0 )
{
}
template< typename T >
inline const T& WMatrixSymImpl< T >::operator()( size_t i, size_t j ) const throw( WOutOfBounds )
inline const T& WMatrixSym< T >::operator()( size_t i, size_t j ) const throw( WOutOfBounds )
{
if( i == j || i >= m_n || j >= m_n )
{
......@@ -150,7 +170,7 @@ inline const T& WMatrixSymImpl< T >::operator()( size_t i, size_t j ) const thro
template< typename T >
inline T& WMatrixSymImpl< T >::operator()( size_t i, size_t j ) throw( WOutOfBounds )
inline T& WMatrixSym< T >::operator()( size_t i, size_t j ) throw( WOutOfBounds )
{
if( i == j || i >= m_n || j >= m_n )
{
......@@ -165,57 +185,135 @@ inline T& WMatrixSymImpl< T >::operator()( size_t i, size_t j ) throw( WOutOfBou
return m_data[( i * m_n + j - ( i + 1 ) * ( i + 2 ) / 2 )];
}
template< typename T >
inline std::string WMatrixSymImpl< T >::toString( void ) const
inline std::string WMatrixSym< T >::toString( void ) const
{
std::stringstream ss;
ss.precision( 3 );
ss << std::fixed;
for( size_t i = 0; i < m_n; ++i )
std::stringstream ss;
ss << std::setprecision( 9 ) << std::fixed;
ss << *this;
return ss.str();
}
/**
* Compares two matrix elementwise. First tested their size, if equal elementwisely further tests.
*
* \tparam T Element type
* \param lhs Left symmetric matrix operand
* \param rhs Right symmetric matrix operand
*
* \return True if and only if all elements are equal.
*/
template< typename T >
inline bool operator==( WMatrixSym< T > const& lhs, WMatrixSym< T > const& rhs )
{
std::vector< T > l = lhs.getData();
std::vector< T > r = rhs.getData();
return l == r;
}
/**
* Output operator for symmetric Matrix producing full square matrix. Each row in separate line.
*
* \tparam T Element type
* \param os Output stream
* \param m Matrix to put to output stream
*
* \return Output stream
*/
template< typename T >
inline std::ostream& operator<<( std::ostream& os, const WMatrixSym< T >& m )
{
size_t n = m.size();
for( size_t i = 0; i < n; ++i )
{
for( size_t j = 0; j < m_n; ++j )
for( size_t j = 0; j < n; ++j )
{
if( i != j )
{
ss << this->operator()(i,j);
os << m( i, j );
}
else
{
ss << "0.0";
os << 0.0;
}
if( ( j + 1 ) < m_n )
if( ( j + 1 ) < n )
{
ss << " ";
os << " ";
}
}
if( ( i + 1 ) < m_n )
if( ( i + 1 ) < n )
{
ss << std::endl;
os << std::endl;
}
}
return os;
}
/**
* Read elemnts of full square matrix into symmetric matrix. Only elements of the upper triangle matrix will be used.
* First all elements separated by white space are read and then dimension check is performed, to ensure all
* elements fit into sym Matrix then.
*
* \throw WOutOfBounds exception if element number missmatch occours.
*
* \tparam T Element type
* \param is Input Stream
* \param m Sym. Matrix to populate
*
* \return Input Stream
*/
template< typename T >
inline std::istream& operator>>( std::istream& is, WMatrixSym< T >& m )
{
std::vector< T > elements;
T elm;
while( is >> elm )
{
elements.push_back( elm );
}
if( m.size() * m.size() != elements.size() )
{
std::stringstream ss;
ss << "Error: Input stream has: " << elements.size() << " elements, while matrix given to accommodate expected: ";
ss << m.size() * m.size() << " elements.";
throw WOutOfBounds( ss.str() );
}
typename std::vector< T >::const_iterator it = elements.begin();
for( size_t i = 0; i < m.size(); ++i )
{
for( size_t j = 0; j < m.size(); ++j )
{
if( j > i )
{
m( i, j ) = *it;
}
++it;
}
}
return ss.str();
return is;
}
template< typename T >
inline size_t WMatrixSymImpl< T >::numElements() const
inline size_t WMatrixSym< T >::numElements() const
{
return m_data.size();
}
template< typename T >
inline size_t WMatrixSymImpl< T >::size() const
inline size_t WMatrixSym< T >::size() const
{
return m_n;
}
template< typename T >
inline const typename std::vector< T >& WMatrixSymImpl< T >::getData() const
inline const typename std::vector< T >& WMatrixSym< T >::getData() const
{
return m_data;
}
template< typename T >
inline void WMatrixSymImpl< T >::setData( const std::vector< T > &data ) throw( WOutOfBounds )
inline void WMatrixSym< T >::setData( const std::vector< T > &data ) throw( WOutOfBounds )
{
if( m_n * ( m_n - 1 ) / 2 != data.size() )
{
......@@ -226,7 +324,7 @@ inline void WMatrixSymImpl< T >::setData( const std::vector< T > &data ) throw(
m_data = std::vector< T >( data ); // copy content
}
typedef WMatrixSymImpl< double > WMatrixSymDBL;
typedef WMatrixSymImpl< float > WMatrixSymFLT;
typedef WMatrixSym< double > WMatrixSymDBL;
typedef WMatrixSym< float > WMatrixSymFLT;
#endif // WMATRIXSYM_H
......@@ -2,7 +2,7 @@
//
// Project: OpenWalnut ( http://www.openwalnut.org )
//
// Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
// Copyright 2013 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
// For more information see http://www.openwalnut.org/copying
//
// This file is part of OpenWalnut.
......@@ -25,14 +25,50 @@
#ifndef WMATRIXSYM_TEST_H
#define WMATRIXSYM_TEST_H
#include <sstream>
#include <string>
#include <vector>
#include <cxxtest/TestSuite.h>
#include <cxxtest/ValueTraits.h>
#include "../../exceptions/WOutOfBounds.h"
#include "../../test/WTraitsBase.h"
#include "../WMatrixSym.h"
#ifdef CXXTEST_RUNNING
namespace CxxTest
{
CXXTEST_TEMPLATE_INSTANTIATION
/**
* Enables better UnitTest OutPut if something fails with WFibers, so you see
* immedeatly what is failing.
*/
class ValueTraits< WMatrixSym< double > > : public WTraitsBase
{
public:
/**
* Constructor for class allowing usable output of WMatrix in tests
*
* \param m the WMatrix to print
*/
explicit ValueTraits( const WMatrixSym< double > &m )
{
std::stringstream tmp;
tmp.precision( 5 );
for( size_t row = 0; row < m.size(); row++ )
{
for( size_t col = row + 1; col < m.size(); col++ )
{
tmp << m( row, col ) << " ";
}
}
m_s = tmp.str();
}
};
}
#endif // CXXTEST_RUNNING
/**
* Unit test this LookUp table class. All test performed on matrices with double as element type.
*/
......@@ -85,15 +121,49 @@ public:
"Invalid Element Access ( 0, 0 ). No diagonal elements or indices bigger than 4 are allowed." );
}
/**
* Renders the matrix to a string, where each row is in a separate line.
*/
void testToString( void )
{
WMatrixSymDBL t( 3 );
double mydata[] = { 1.6, 0.2, 1/3.0 }; // NOLINT
std::vector< double > data( mydata, mydata + sizeof( mydata ) / sizeof( double ) );
t.setData( data );
std::string expected = "0.0 1.600 0.200\n1.600 0.0 0.333\n0.200 0.333 0.0";
std::string expected = "0.000000000 1.600000000 0.200000000\n1.600000000 0.000000000 0.333333333\n0.200000000 0.333333333 0.000000000";
TS_ASSERT_EQUALS( expected, t.toString() );
}
/**
* There should be an output operator for symmetric matrices.
*/
void testOutputStream( void )
{
WMatrixSymDBL t( 3 );
double mydata[] = { 1.6, 0.2, 1/3.0 }; // NOLINT
std::vector< double > data( mydata, mydata + sizeof( mydata ) / sizeof( double ) );
t.setData( data );
std::string expected = "0.00 1.60 0.20\n1.60 0.00 0.33\n0.20 0.33 0.00";
std::stringstream ss;
ss << std::setprecision( 2 ) << std::fixed;
ss << t;
TS_ASSERT_EQUALS( expected, ss.str() );
}
/**
* There should be an input operator for symmetric matrices, reading data into a given matrix.
*/
void testInputStream( void )
{
WMatrixSymDBL expected( 3 );
double mydata[] = { 1.6, 0.2, 0.3 }; // NOLINT
std::vector< double > data( mydata, mydata + sizeof( mydata ) / sizeof( double ) );
expected.setData( data );
std::stringstream ss( "0.0 1.6 0.2\n1.6 0.0 0.3\n0.2 0.3 0.0" );
WMatrixSymDBL actual( 3 );
ss >> actual;
TS_ASSERT_EQUALS( expected, actual );
}
};
#endif // WMATRIXSYM_TEST_H
......@@ -108,6 +108,20 @@ public:
WGridRegular3DTemplate( unsigned int nbPosX, unsigned int nbPosY, unsigned int nbPosZ,
WGridTransformOrthoTemplate< T > const transform = WGridTransformOrthoTemplate< T >() );
/**
* Defines the number of samples in each coordinate direction as ints,
* and the transformation of the grid via a grid transform.
*
* \param nbPosX number of positions along first axis
* \param nbPosY number of positions along second axis
* \param nbPosZ number of positions along third axis
* \param scaleX scaling of a voxel in x direction
* \param scaleY scaling of a voxel in y direction
* \param scaleZ scaling of a voxel in z direction
*/
WGridRegular3DTemplate( unsigned int nbPosX, unsigned int nbPosY, unsigned int nbPosZ,
double scaleX, double scaleY, double scaleZ );
/**
* Returns the number of samples in x direction.
* \return The number of samples in x direction.
......@@ -557,6 +571,18 @@ WGridRegular3DTemplate< T >::WGridRegular3DTemplate( unsigned int nbPosX, unsign
initInformationProperties();
}
template< typename T >
WGridRegular3DTemplate< T >::WGridRegular3DTemplate( unsigned int nbPosX, unsigned int nbPosY, unsigned int nbPosZ,
double scaleX, double scaleY, double scaleZ ):
WGrid( nbPosX * nbPosY * nbPosZ ),
m_nbPosX( nbPosX ),
m_nbPosY( nbPosY ),
m_nbPosZ( nbPosZ ),
m_transform( WGridTransformOrthoTemplate< T >( scaleX, scaleY, scaleZ ) )
{
initInformationProperties();
}
template< typename T >
inline unsigned int WGridRegular3DTemplate< T >::getNbCoordsX() const
{
......
......@@ -47,8 +47,8 @@
#include "WGENoOpManipulator.h"
#include "WGEZoomTrackballManipulator.h"
#include "WPickHandler.h"
#include "../common/WConditionOneShot.h"
#include "../common/WConditionOneShot.h"
#include "../common/WThreadedRunner.h"
#include "WGEViewer.h"
......@@ -60,7 +60,10 @@ WGEViewer::WGEViewer( std::string name, osg::ref_ptr<osg::Referenced> wdata, int
m_name( name ),
m_rendered( WBoolFlag::SPtr( new WBoolFlag( new WConditionOneShot(), false ) ) ),
m_screenCapture( new WGEScreenCapture() ),
m_inAnimationMode( false )
m_inAnimationMode( false ),
m_effectHorizon( new WGEViewerEffectHorizon() ),
m_effectVignette( new WGEViewerEffectVignette() ),
m_effectImageOverlay( new WGEViewerEffectImageOverlay() )
{
try
{
......@@ -160,6 +163,11 @@ void WGEViewer::setScene( osg::ref_ptr< WGEGroupNode > node )
{
m_View->setSceneData( node );
m_scene = node;
// add effects:
node->insert( m_effectVignette );
node->insert( m_effectImageOverlay );
node->insert( m_effectHorizon );
}
osg::ref_ptr< WGEGroupNode > WGEViewer::getScene()
......@@ -294,3 +302,32 @@ bool WGEViewer::isAnimationMode() const
return m_inAnimationMode;
}
WGEViewerEffectHorizon::SPtr WGEViewer::getBackground()
{
return m_effectHorizon;
}
WGEViewerEffectImageOverlay::SPtr WGEViewer::getImageOverlay()
{
return m_effectImageOverlay;
}
WGEViewerEffectVignette::SPtr WGEViewer::getVignette()
{
return m_effectVignette;
}
WGEViewerEffectHorizon::ConstSPtr WGEViewer::getBackground() const
{
return m_effectHorizon;
}
WGEViewerEffectImageOverlay::ConstSPtr WGEViewer::getImageOverlay() const
{
return m_effectImageOverlay;
}
WGEViewerEffectVignette::ConstSPtr WGEViewer::getVignette() const
{
return m_effectVignette;
}
......@@ -59,13 +59,17 @@ class WGEGroupNode;
class WPickHandler;
#include "animation/WGEAnimationManipulator.h"
#include "WGEViewerEffectHorizon.h"
#include "WGEViewerEffectVignette.h"
#include "WGEViewerEffectImageOverlay.h"
/**
* Class for managing one view to the scene. This includes viewport, camera and graphics context.
* It is, besides WGraphicsEngine, the ONLY entry point for each widget for accessing the graphics engine.
* \ingroup ge
*/
class WGEViewer: public WGEGraphicsWindow,
public boost::enable_shared_from_this< WGEViewer >
public boost::enable_shared_from_this< WGEViewer >
{
public:
/**
......@@ -183,6 +187,9 @@ public:
/**
* Determine the color of the viewer's background.
*
* \note This is only useful when the background effect is disabled.
*
* \param bgColor the new background color
*/
void setBgColor( const WColor& bgColor );
......@@ -237,6 +244,48 @@ public:
*/
bool isAnimationMode() const;
/**
* Return the background render effect for modification.
*
* \return the effect
*/
WGEViewerEffectHorizon::SPtr getBackground();
/**
* Return the overlay render effect for modification.
*
* \return the effect
*/
WGEViewerEffectImageOverlay::SPtr getImageOverlay();
/**
* Return the vignette render effect for modification.
*
* \return the effect
*/
WGEViewerEffectVignette::SPtr getVignette();
/**
* Return the background render effect for modification.
*
* \return the effect
*/
WGEViewerEffectHorizon::ConstSPtr getBackground() const;
/**
* Return the overlay render effect for modification.
*
* \return the effect
*/
WGEViewerEffectImageOverlay::ConstSPtr getImageOverlay() const;
/**
* Return the vignette render effect for modification.
*
* \return the effect
*/
WGEViewerEffectVignette::ConstSPtr getVignette() const;
protected:
/**
* The OpenSceneGraph view used in this (Composite)Viewer.
......@@ -338,6 +387,20 @@ protected:
*/
osg::ref_ptr<osgGA::MatrixManipulator> m_animationModeManipulatorBackup;
/**
* Horizon effect.
*/
WGEViewerEffectHorizon::SPtr m_effectHorizon;
/**
* Vignette effect.
*/
WGEViewerEffectVignette::SPtr m_effectVignette;
/**
* Image overlay effect.
*/
WGEViewerEffectImageOverlay::SPtr m_effectImageOverlay;
private:
};
......
//---------------------------------------------------------------------------
//
// 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 <osg/Depth>