Commit cc296e75 authored by Sebastian Eichelbaum's avatar Sebastian Eichelbaum
Browse files

[ADD] - added transformation property to WGETExture.

parent 8ce20ad6
......@@ -156,6 +156,11 @@ WPropGroup WPropertyBase::toPropGroup()
return boost::shared_static_cast< WPVGroup >( shared_from_this() );
}
WPropMatrix4X4 WPropertyBase::toPropMatrix4X4()
{
return boost::shared_static_cast< WPVMatrix4X4 >( shared_from_this() );
}
WPropTrigger WPropertyBase::toPropTrigger()
{
return boost::shared_static_cast< WPVTrigger >( shared_from_this() );
......
......@@ -245,6 +245,13 @@ public:
*/
WPropTrigger toPropTrigger();
/**
* Helper converts this instance to its native type.
*
* \return the property as matrix4x4 property
*/
WPropMatrix4X4 toPropMatrix4X4();
/**
* Helper converts this instance to its native type.
*
......
......@@ -35,6 +35,7 @@
#include <boost/lexical_cast.hpp>
#include "math/WPosition.h"
#include "math/WMatrix4x4.h"
#include "WItemSelector.h"
#include "WColor.h"
......@@ -65,7 +66,8 @@ typedef enum
PV_SELECTION, //!< a list of strings, selectable
PV_POSITION, //!< a position property
PV_COLOR, //!< a color property
PV_TRIGGER //!< for triggering an event
PV_TRIGGER, //!< for triggering an event
PV_MATRIX4X4 //!< for 4x4 matrices
}
PROPERTY_TYPE;
......@@ -98,6 +100,7 @@ namespace WPVBaseTypes
typedef WItemSelector PV_SELECTION; //!< base type used for every WPVSelection
typedef wmath::WPosition PV_POSITION; //!< base type used for every WPVPosition
typedef WColor PV_COLOR; //!< base type used for every WPVColor
typedef wmath::WMatrix4x4 PV_MATRIX4X4; //!< base type used for every WPVMatrix4X4
/**
* Enum denoting the possible trigger states. It is used for trigger properties.
......@@ -186,6 +189,11 @@ typedef WPropertyVariable< WPVBaseTypes::PV_COLOR > WPVColor;
*/
typedef WPropertyVariable< WPVBaseTypes::PV_TRIGGER > WPVTrigger;
/**
* Trigger properties
*/
typedef WPropertyVariable< WPVBaseTypes::PV_MATRIX4X4 > WPVMatrix4X4;
/**
* Some convenience type alias for a even more easy usage of WPropertyVariable.
* These typdefs define some pointer alias.
......@@ -241,6 +249,12 @@ typedef boost::shared_ptr< WPVGroup > WPropGroup;
*/
typedef boost::shared_ptr< WPVTrigger > WPropTrigger;
/**
* Alias for the 4x4 matrix properties.
*/
typedef boost::shared_ptr< WPVMatrix4X4 > WPropMatrix4X4;
/**
* This namespace contains several helper classes which translate their template type to an enum.
*/
......@@ -270,7 +284,7 @@ namespace PROPERTY_TYPE_HELPER
* You only need to specialize this class for types not allowing the direct use of boost::lexical_cast.
*/
template< typename T >
class WCreateFromString
class WStringConversion
{
public:
/**
......@@ -284,6 +298,18 @@ namespace PROPERTY_TYPE_HELPER
{
return boost::lexical_cast< T >( str );
}
/**
* Creates a string from the specified value.
*
* \param v the value to convert
*
* \return the string representation
*/
std::string asString( const T& v )
{
return boost::lexical_cast< std::string >( v );
}
};
/**
......@@ -399,7 +425,7 @@ namespace PROPERTY_TYPE_HELPER
* serializable content which needs to be acquired from its predecessor instance.
*/
template<>
class WCreateFromString< WPVBaseTypes::PV_SELECTION >
class WStringConversion< WPVBaseTypes::PV_SELECTION >
{
public:
/**
......@@ -414,6 +440,18 @@ namespace PROPERTY_TYPE_HELPER
{
return old.newSelector( str );
}
/**
* Creates a string from the specified value.
*
* \param v the value to convert
*
* \return the string representation
*/
std::string asString( const WPVBaseTypes::PV_SELECTION& v )
{
return boost::lexical_cast< std::string >( v );
}
};
/**
......@@ -469,6 +507,58 @@ namespace PROPERTY_TYPE_HELPER
return PV_TRIGGER;
}
};
/**
* Class helping to adapt types specified as template parameter into an enum.
*/
template<>
class WTypeIdentifier< WPVBaseTypes::PV_MATRIX4X4 >
{
public:
/**
* Get type identifier of the template type T.
*
* \return type identifier-
*/
PROPERTY_TYPE getType()
{
return PV_MATRIX4X4;
}
};
/**
* Class helping to create a new instance of the property content from an old one. Selections need this special care since they contain not
* serializable content which needs to be acquired from its predecessor instance.
*/
template<>
class WStringConversion< WPVBaseTypes::PV_MATRIX4X4 >
{
public:
/**
* Creates a new instance of the type from a given string. Some classes need a predecessor which is also specified here.
*
* \param old the old value
* \param str the new value as string
*
* \return the new instance
*/
WPVBaseTypes::PV_MATRIX4X4 create( const WPVBaseTypes::PV_MATRIX4X4& /*old*/, const std::string str )
{
return wmath::fromString( str );
}
/**
* Creates a string from the specified value.
*
* \param v the value to convert
*
* \return the string representation
*/
std::string asString( const WPVBaseTypes::PV_MATRIX4X4& v )
{
return wmath::toString( v );
}
};
}
#endif // WPROPERTYTYPES_H
......@@ -574,7 +574,7 @@ bool WPropertyVariable< T >::setAsString( std::string value )
try
{
// use the helper class which can handle different kinds of properties for us
PROPERTY_TYPE_HELPER::WCreateFromString< T > h = PROPERTY_TYPE_HELPER::WCreateFromString< T >();
PROPERTY_TYPE_HELPER::WStringConversion< T > h = PROPERTY_TYPE_HELPER::WStringConversion< T >();
WFlag< T >::set( h.create( WFlag< T >::get(), value ) );
}
catch( const boost::bad_lexical_cast &e )
......@@ -589,8 +589,9 @@ template < typename T >
std::string WPropertyVariable< T >::getAsString()
{
std::string val;
val = boost::lexical_cast< std::string >( WFlag< T >::get() );
// try catch( const boost::bad_lexical_cast &e ) ? No if this happens something is wrong with the value
// use the helper class which can handle different kinds of properties for us
PROPERTY_TYPE_HELPER::WStringConversion< T > h = PROPERTY_TYPE_HELPER::WStringConversion< T >();
return h.asString( WFlag< T >::get() );
return val;
}
......
//---------------------------------------------------------------------------
//
// 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 "WMatrix4x4.h"
//---------------------------------------------------------------------------
//
// 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 WMATRIX4X4_H
#define WMATRIX4X4_H
#include <string>
#include <boost/lexical_cast.hpp>
#include <osg/Matrix>
#include <osg/io_utils>
#include "../WStringUtils.h"
#include "../WAssert.h"
namespace wmath
{
/**
* Use osg 4x4 matrices as WMatrix4x4
*/
typedef osg::Matrixd WMatrix4x4;
/**
* Write a 4x4 matrix in string representation.
*
* \param c the matrix
*
* \return the matrix as string
*/
inline std::string toString( const WMatrix4x4& c )
{
std::ostringstream out;
for ( size_t row = 0; row < 4; ++row )
{
for ( size_t col = 0; col < 4; ++col )
{
out << c( row, col ) << ";";
}
}
return out.str();
}
/**
* Read a 4x4 matrix in string representation from the given string.
*
* \param str the string to parse
*
* \return the matrix
*/
inline WMatrix4x4 fromString( std::string str )
{
WMatrix4x4 c;
std::vector<std::string> tokens;
tokens = string_utils::tokenize( str, ";" );
WAssert( tokens.size() >= 16, "There weren't 16 values for a 4x4 Matrix" );
size_t idx = 0;
for ( size_t row = 0; row < 4; ++row )
{
for ( size_t col = 0; col < 4; ++col )
{
c( row, col ) = boost::lexical_cast< double >( tokens[ idx ] );
idx++;
}
}
return c;
}
}
#endif // WMATRIX4X4_H
......@@ -52,12 +52,6 @@ WDataTexture3D_2::~WDataTexture3D_2()
// cleanup
}
osg::Matrix WDataTexture3D_2::getTexMatrix() const
{
// TODO(ebaum): implement this, use grid
return osg::Matrix::identity();
}
void WDataTexture3D_2::create()
{
osg::ref_ptr< osg::Image > ima;
......
......@@ -122,14 +122,6 @@ public:
*/
boost::shared_ptr< WGridRegular3D > getGrid() const;
/**
* Returns the matrix used for transforming the texture coordinates to match the texture. This method calculates the correct texture matrix
* by using the grid's transformation.
*
* \return the matrix allowing direct application to osg::TexMat.
*/
virtual osg::Matrix getTexMatrix() const;
protected:
/**
......
......@@ -41,6 +41,7 @@
#include "../common/WLimits.h"
#include "../common/WProperties.h"
#include "../common/WPropertyHelper.h"
#include "../common/math/WMatrix4x4.h"
#include "WGETextureUtils.h"
......@@ -141,11 +142,11 @@ public:
WPropBool active() const;
/**
* Returns the matrix used for transforming the texture coordinates to match the texture.
* Returns the texture transformation matrix. The property can be changed. A change affects all colormaps using this texture.
*
* \return the matrix allowing direct application to osg::TexMat.
* \return the matrix
*/
virtual osg::Matrix getTexMatrix() const;
WPropMatrix4X4 transformation() const;
/**
* Binds the texture to the specified node and texture unit. It also adds two uniforms: u_textureXMin and u_textureXScale, where X
......@@ -273,6 +274,11 @@ private:
* True if the texture is active.
*/
WPropBool m_active;
/**
* The texture transformation matrix.
*/
WPropMatrix4X4 m_texMatrix;
};
// Some convenience typedefs
......@@ -364,6 +370,8 @@ void WGETexture< TextureType >::setupProperties( double scale, double min )
m_active = m_properties->addProperty( "Active", "Can dis-enable a texture.", true, m_propCondition );
m_texMatrix = m_properties->addProperty( "Texture Transformation", "Usable to transform the texture.", osg::Matrix::identity(), m_propCondition );
TextureType::setResizeNonPowerOfTwoHint( false );
TextureType::setUpdateCallback( new WGEFunctorCallback< osg::StateAttribute >(
boost::bind( &WGETexture< TextureType >::updateCallback, this, _1 ) )
......@@ -436,6 +444,12 @@ inline WPropBool WGETexture< TextureType >::active() const
return m_active;
}
template < typename TextureType >
inline WPropMatrix4X4 WGETexture< TextureType >::transformation() const
{
return m_texMatrix;
}
template < typename TextureType >
void WGETexture< TextureType >::handleUpdate()
{
......@@ -464,12 +478,6 @@ void WGETexture< TextureType >::bind( osg::ref_ptr< osg::Node > node, size_t uni
wge::bindTexture( node, osg::ref_ptr< WGETexture< TextureType > >( this ), unit ); // to avoid recursive stuff -> explicitly specify the type
}
template < typename TextureType >
osg::Matrix WGETexture< TextureType >::getTexMatrix() const
{
return osg::Matrix::identity();
}
template < typename TextureType >
void WGETexture< TextureType >::create()
{
......
......@@ -29,6 +29,7 @@
#include <osg/Node>
#include <osg/StateSet>
#include <osg/TexMat>
#include <boost/lexical_cast.hpp>
......@@ -120,6 +121,9 @@ void wge::bindTexture( osg::ref_ptr< osg::Node > node, osg::ref_ptr< WGETexture<
wge::bindTexture< T >( node, osg::ref_ptr< T >( texture ), unit, prefix );
// set the texture matrix to the stateset
// node->getOrCreateStateSet()->setTextureAttributeAndModes( unit, new osg::TexMat( texture->getTexMatrix() ), osg::StateAttribute::ON );
// add some additional uniforms containing scaling information
texture->applyUniforms( prefix, node->getOrCreateStateSet() );
}
......
......@@ -28,6 +28,7 @@ SET(GUI_QT4_MOC_HDRS
controlPanel/WPropertyTriggerWidget.h
controlPanel/WPropertySelectionWidget.h
controlPanel/WPropertyPositionWidget.h
controlPanel/WPropertyMatrix4X4Widget.h
controlPanel/WQtControlPanel.h
controlPanel/WQtPropertyGroupWidget.h
controlPanel/WQtTreeWidget.h
......
//---------------------------------------------------------------------------
//
// 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 <sstream>
#include <cmath>
#include <string>
#include <boost/lexical_cast.hpp>
#include "../../../common/WLogger.h"
#include "../../../common/WPropertyVariable.h"
#include "WPropertyMatrix4X4Widget.h"
WPropertyMatrix4X4Widget::WPropertyMatrix4X4Widget( WPropMatrix4X4 property, QGridLayout* propertyGrid, QWidget* parent ):
WPropertyWidget( property, propertyGrid, parent ),
m_matrixProperty( property ),
m_layout( &m_parameterWidgets ),
m_asText( &m_informationWidgets ),
m_infoLayout( &m_informationWidgets )
{
// initialize members
/*m_editX.resize( m_editX.minimumSizeHint().width() * 2.0, m_editX.size().height() );
//m_editX.setMaximumWidth( m_editX.minimumSizeHint().width() * 5.0 );
m_editY.resize( m_editY.minimumSizeHint().width() * 2.0, m_editY.size().height() );
//m_editY.setMaximumWidth( m_editY.minimumSizeHint().width() * 5.0 );
m_editZ.resize( m_editZ.minimumSizeHint().width() * 2.0, m_editZ.size().height() );
//m_editZ.setMaximumWidth( m_editZ.minimumSizeHint().width() * 5.0 );
// layout both against each other
m_layout.addWidget( &m_editX );
m_layout.addWidget( &m_editY );
m_layout.addWidget( &m_editZ );
m_parameterWidgets.setLayout( &m_layout );
// Information Output ( Property Purpose = PV_PURPOSE_INFORMATION )
m_infoLayout.addWidget( &m_asText );
m_informationWidgets.setLayout( &m_infoLayout );
update();
// connect the modification signal of the edit and slider with our callback
connect( &m_editX, SIGNAL( returnPressed() ), this, SLOT( editChanged() ) );
connect( &m_editX, SIGNAL( textEdited( const QString& ) ), this, SLOT( textEdited( const QString& ) ) );
connect( &m_editY, SIGNAL( returnPressed() ), this, SLOT( editChanged() ) );
connect( &m_editY, SIGNAL( textEdited( const QString& ) ), this, SLOT( textEdited( const QString& ) ) );
connect( &m_editZ, SIGNAL( returnPressed() ), this, SLOT( editChanged() ) );
connect( &m_editZ, SIGNAL( textEdited( const QString& ) ), this, SLOT( textEdited( const QString& ) ) );*/
}
WPropertyMatrix4X4Widget::~WPropertyMatrix4X4Widget()
{
// cleanup
}
void WPropertyMatrix4X4Widget::update()
{
// set the values
/*m_editX.setText( QString::fromStdString( toString( m_matProperty->get()[0] ) ) );
m_editY.setText( QString::fromStdString( toString( m_matProperty->get()[1] ) ) );
m_editZ.setText( QString::fromStdString( toString( m_matProperty->get()[2] ) ) );
// do not forget to update the label
m_asText.setText( QString::fromStdString( toString( m_matProperty->get() ) ) );*/
}
void WPropertyMatrix4X4Widget::editChanged()
{
//setPropertyFromWidgets();
}
void WPropertyMatrix4X4Widget::textEdited( const QString& /*text*/ )
{
//setPropertyFromWidgets( true );
}
void WPropertyMatrix4X4Widget::setPropertyFromWidgets( bool validateOnly )
{
/* // grab all the values
bool valid;
double valueX = m_editX.text().toDouble( &valid );
if ( !valid )
{
invalidate();
return;
}
double valueY = m_editY.text().toDouble( &valid );
if ( !valid )
{
invalidate();
return;
}
double valueZ = m_editZ.text().toDouble( &valid );
if ( !valid )
{
invalidate();
return;
}
// create a new position
wmath::WPosition p = wmath::WPosition( valueX, valueY, valueZ );
// set/validate to the property
if ( validateOnly )
{
invalidate( !m_posProperty->accept( p ) );
}
else
{
invalidate( !m_posProperty->set( p ) ); // NOTE: set automatically checks the validity of the value
}*/
}
//---------------------------------------------------------------------------
//
// 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 WPROPERTYMATRIX4X4WIDGET_H
#define WPROPERTYMATRIX4X4WIDGET_H
#include <string>
#include <QtGui/QLineEdit>
#include <QtGui/QSlider>