Commit 687f73ad authored by Sebastian Eichelbaum's avatar Sebastian Eichelbaum

[CHANGE] - colormapper, textures and properties switched to new MAtrix4x4

parent bd00c44a
......@@ -27,6 +27,11 @@
#include <stdint.h>
#include <string>
#include <vector>
#include <boost/lexical_cast.hpp>
#include <string>
#include <list>
#include <utility>
......@@ -35,7 +40,7 @@
#include <boost/lexical_cast.hpp>
#include "math/WPosition.h"
#include "math/WMatrix4x4.h"
#include "math/WMatrix.h"
#include "WItemSelector.h"
#include "WColor.h"
......@@ -98,9 +103,9 @@ namespace WPVBaseTypes
typedef std::string PV_STRING; //!< base type used for every WPVString
typedef boost::filesystem::path PV_PATH; //!< base type used for every WPVFilename
typedef WItemSelector PV_SELECTION; //!< base type used for every WPVSelection
typedef WPosition PV_POSITION; //!< base type used for every WPVPosition
typedef WPosition PV_POSITION; //!< base type used for every WPVPosition
typedef WColor PV_COLOR; //!< base type used for every WPVColor
typedef WMatrix4x4 PV_MATRIX4X4; //!< base type used for every WPVMatrix4X4
typedef WMatrix4x4_2 PV_MATRIX4X4; //!< base type used for every WPVMatrix4X4
/**
* Enum denoting the possible trigger states. It is used for trigger properties.
......@@ -543,7 +548,22 @@ namespace PROPERTY_TYPE_HELPER
*/
WPVBaseTypes::PV_MATRIX4X4 create( const WPVBaseTypes::PV_MATRIX4X4& /*old*/, const std::string str )
{
return fromString( str );
WMatrix4x4_2 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;
}
/**
......@@ -555,7 +575,64 @@ namespace PROPERTY_TYPE_HELPER
*/
std::string asString( const WPVBaseTypes::PV_MATRIX4X4& v )
{
return toString( v );
std::ostringstream out;
for ( size_t row = 0; row < 4; ++row )
{
for ( size_t col = 0; col < 4; ++col )
{
out << v( row, col ) << ";";
}
}
return out.str();
}
};
/**
* 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_POSITION >
{
public:
/**
* Creates a new instance of the type from a given string. Some classes need a predecessor which is also specified here.
*
* \param str the new value as string
*
* \return the new instance
*/
WPVBaseTypes::PV_POSITION create( const WPVBaseTypes::PV_POSITION& /*old*/, const std::string str )
{
WPVBaseTypes::PV_POSITION c;
std::vector< std::string > tokens;
tokens = string_utils::tokenize( str, ";" );
WAssert( tokens.size() >= 3, "There weren't 3 values for a 3D vector" );
size_t idx = 0;
for ( size_t col = 0; col < 3; ++col )
{
c[ col ] = boost::lexical_cast< double >( tokens[ idx ] );
idx++;
}
return c;
}
/**
* Creates a string from the specified value.
*
* \param v the value to convert
*
* \return the string representation
*/
std::string asString( const WPVBaseTypes::PV_POSITION& v )
{
std::ostringstream out;
for ( size_t col = 0; col < 3; ++col )
{
out << v[ col ] << ";";
}
return out.str();
}
};
}
......
......@@ -33,6 +33,7 @@
#include "../WDefines.h"
#include "../../ext/Eigen/Core"
#include "../../ext/Eigen/LU"
/**
* A double 3 times 3 matrix. Stack-allocated. Column Major!
......@@ -81,6 +82,26 @@ typedef Eigen::MatrixXd WMatrix_2;
*/
typedef Eigen::MatrixXcd WMatrixComplex_2;
/**
* Converts a given WMatrix4x4_2 to an osg matrix.
*
* \param m the matrix to convert
*
* \return the converted matrix
*/
inline osg::Matrixd toOsgMatrixd( WMatrix4x4_2 m )
{
osg::Matrixd m2;
for ( size_t row = 0; row < 4; ++row )
{
for ( size_t col = 0; col < 4; ++col )
{
m2( row, col ) = m( row, col );
}
}
return m2;
}
/**
* Matrix template class with variable number of rows and columns.
* The access function are row-major, which means that the rows
......
......@@ -50,7 +50,7 @@ OW_API_DEPRECATED typedef osg::Matrixd WMatrix4x4;
*
* \return the matrix as string
*/
inline std::string toString( const WMatrix4x4& c )
/*inline std::string toString( const WMatrix4x4& c )
{
std::ostringstream out;
for ( size_t row = 0; row < 4; ++row )
......@@ -62,7 +62,7 @@ inline std::string toString( const WMatrix4x4& c )
}
return out.str();
}
*/
/**
* Read a 4x4 matrix in string representation from the given string.
*
......@@ -70,7 +70,7 @@ inline std::string toString( const WMatrix4x4& c )
*
* \return the matrix
*/
inline WMatrix4x4 fromString( std::string str )
/*inline WMatrix4x4 fromString( std::string str )
{
WMatrix4x4 c;
std::vector< std::string > tokens;
......@@ -88,6 +88,6 @@ inline WMatrix4x4 fromString( std::string str )
}
return c;
}
}*/
#endif // WMATRIX4X4_H
......@@ -22,7 +22,7 @@
//
//---------------------------------------------------------------------------
#include "../common/math/WMatrix4x4.h"
#include "../common/math/WMatrix.h"
#include "WValueSet.h"
......@@ -49,19 +49,19 @@ WDataTexture3D_2::WDataTexture3D_2( boost::shared_ptr< WValueSetBase > valueSet,
threshold()->set( valueSet->getMinimumValue() );
// Scale according to bbox. This scaling is NOT included in the grid's transform, so we need to add it here
WMatrix4x4 scale;
WMatrix4x4_2 scale = WMatrix4x4_2::Zero();
scale( 0, 0 ) = 1.0 / grid->getNbCoordsX();
scale( 1, 1 ) = 1.0 / grid->getNbCoordsY();
scale( 2, 2 ) = 1.0 / grid->getNbCoordsZ();
scale( 3, 3 ) = 1.0;
// Move to voxel center. This scaling is NOT included in the grid's transform, so we need to add it here
WMatrix4x4 offset = WMatrix4x4::identity();
WMatrix4x4_2 offset = WMatrix4x4_2::Identity();
offset( 0, 3 ) = 0.5 / grid->getNbCoordsX();
offset( 1, 3 ) = 0.5 / grid->getNbCoordsY();
offset( 2, 3 ) = 0.5 / grid->getNbCoordsZ();
transformation()->set( WMatrix4x4::inverse( grid->getTransform() ) * scale * offset );
transformation()->set( offset * scale * static_cast< WMatrix4x4_2 >( grid->getTransform() ).inverse() );
// set the size
WGETexture3D::initTextureSize( this, grid->getNbCoordsX(), grid->getNbCoordsY(), grid->getNbCoordsZ() );
......
......@@ -118,7 +118,7 @@ void WGridRegular3D::initInformationProperties()
WPropDouble yOffset = m_infoProperties->addProperty( "Y offset: ", "The distance between samples in y direction", getOffsetY() );
WPropDouble zOffset = m_infoProperties->addProperty( "Z offset: ", "The distance between samples in z direction", getOffsetZ() );
WPropMatrix4X4 transformation = m_infoProperties->addProperty( "Transformation", "The transformation of this grid.",
static_cast< WMatrix4x4 >( getTransform() ) );
static_cast< WMatrix4x4_2 >( getTransform() ) );
}
int WGridRegular3D::getXVoxelCoord( const WPosition& pos ) const
......
......@@ -35,7 +35,7 @@
#include <osg/Vec3>
#include "../common/math/WMatrix.h"
#include "../common/math/WMatrix4x4.h"
#include "../common/math/WMatrix.h"
#include "../common/math/WPosition.h"
#include "../common/math/WVector3D.h"
#include "../common/WBoundingBox.h"
......@@ -191,20 +191,6 @@ public:
*/
WPosition texCoordToWorldCoord( WVector3D coords );
/**
* Matrix converting a specified world coordinate to texture space according in this grid.
*
* \return the matrix.
*/
const WMatrix4x4& getWorldToTexMatrix() const;
/**
* Matrix converting a specified texture coordinate to world space according to this grid.
*
* \return the matrix.
*/
const WMatrix4x4& getTexToWorldMatrix() const;
/**
* The condition that fires on changes in this grid's transformation matrix.
*
......
......@@ -184,11 +184,9 @@ bool WGridTransformOrtho::isNotRotated() const
&& m_directionZ == WVector3D( 0.0, 0.0, 1.0 );
}
WGridTransformOrtho::operator WMatrix4x4() const
WGridTransformOrtho::operator WMatrix4x4_2() const
{
// NOTE: OSG matrices are row-major!
WMatrix4x4 mat;
mat.makeIdentity();
WMatrix4x4_2 mat = WMatrix4x4_2::Identity();
mat( 0, 0 ) = m_scaling[ 0 ] * m_directionX[ 0 ];
mat( 0, 1 ) = m_scaling[ 0 ] * m_directionX[ 1 ];
mat( 0, 2 ) = m_scaling[ 0 ] * m_directionX[ 2 ];
......
......@@ -27,7 +27,7 @@
#include "../common/math/WVector3D.h"
#include "../common/math/WMatrix.h"
#include "../common/math/WMatrix4x4.h"
#include "../common/math/WMatrix.h"
#include "WExportDataHandler.h"
......@@ -160,7 +160,7 @@ public:
*
* \return the matrix representing the transform
*/
operator WMatrix4x4() const;
operator WMatrix4x4_2() const;
/**
* Check if this transform does not include a rotation.
......
......@@ -108,10 +108,10 @@ boost::shared_ptr< WGEColormapping > WGEColormapping::instance()
void WGEColormapping::apply( osg::ref_ptr< osg::Node > node, osg::ref_ptr< WGEShader > shader, size_t startTexUnit )
{
instance()->applyInst( node, WMatrix4x4::identity(), shader, startTexUnit );
instance()->applyInst( node, WMatrix4x4_2( WMatrix4x4_2::Identity() ), shader, startTexUnit );
}
void WGEColormapping::apply( osg::ref_ptr< osg::Node > node, WMatrix4x4 preTransform, osg::ref_ptr< WGEShader > shader,
void WGEColormapping::apply( osg::ref_ptr< osg::Node > node, WMatrix4x4_2 preTransform, osg::ref_ptr< WGEShader > shader,
size_t startTexUnit )
{
instance()->applyInst( node, preTransform, shader, startTexUnit );
......@@ -133,7 +133,7 @@ void WGEColormapping::replaceTexture( osg::ref_ptr< WGETexture3D > old, osg::ref
instance()->replaceTextureInst( old, newTex, name );
}
void WGEColormapping::applyInst( osg::ref_ptr< osg::Node > node, WMatrix4x4 preTransform, osg::ref_ptr< WGEShader > shader,
void WGEColormapping::applyInst( osg::ref_ptr< osg::Node > node, WMatrix4x4_2 preTransform, osg::ref_ptr< WGEShader > shader,
size_t startTexUnit )
{
// applying to a node simply means adding a callback :-)
......@@ -151,13 +151,13 @@ void WGEColormapping::applyInst( osg::ref_ptr< osg::Node > node, WMatrix4x4 preT
// we use a new instance of the default shader here because the preTransform is varying between several nodes.
osg::ref_ptr< WGEShader > s = new WGEShader( "WGEDefaultColormapper" );
setDefines( s, 0 );
setPreTransform( s, preTransform );
setPreTransform( s, toOsgMatrixd( preTransform ) );
s->apply( node );
}
else
{
setDefines( shader, startTexUnit );
setPreTransform( shader, preTransform );
setPreTransform( shader, toOsgMatrixd( preTransform ) );
shader->apply( node );
}
}
......
......@@ -38,7 +38,7 @@
#include "../common/WBoundingBox.h"
#include "../common/WSharedSequenceContainer.h"
#include "../common/WSharedAssociativeContainer.h"
#include "../common/math/WMatrix4x4.h"
#include "../common/math/WMatrix.h"
#include "callbacks/WGEFunctorCallback.h"
......@@ -111,7 +111,7 @@ public:
* specify any kind of texture coordinates as long as you use this matrix to transform them to the right space.
* \param startTexUnit the first texture unit allowed to be used
*/
static void apply( osg::ref_ptr< osg::Node > node, WMatrix4x4 preTransform = WMatrix4x4::identity(),
static void apply( osg::ref_ptr< osg::Node > node, WMatrix4x4_2 preTransform = WMatrix4x4_2::Identity(),
osg::ref_ptr< WGEShader > shader = osg::ref_ptr< WGEShader >(), size_t startTexUnit = 0 );
/**
......@@ -265,7 +265,7 @@ protected:
* specified, a default shader is used.
* \param startTexUnit the first texture unit allowed to be used
*/
void applyInst( osg::ref_ptr< osg::Node > node, WMatrix4x4 preTransform = WMatrix4x4::identity(),
void applyInst( osg::ref_ptr< osg::Node > node, WMatrix4x4_2 preTransform = WMatrix4x4_2::Identity(),
osg::ref_ptr< WGEShader > shader = osg::ref_ptr< WGEShader >(), size_t startTexUnit = 0 );
/**
......@@ -330,7 +330,7 @@ private:
{
bool m_rebind; //!< true if the node has not been callback'ed before
size_t m_texUnitStart; //!< the start index of the texture unit to use
WMatrix4x4 m_preTransform; //!< matrix used for transforming arbitrary texture coordinates to the proper space.
WMatrix4x4_2 m_preTransform; //!< matrix used for transforming arbitrary texture coordinates to the proper space.
};
/**
......
......@@ -42,7 +42,7 @@
#include "../common/WBoundingBox.h"
#include "../common/WProperties.h"
#include "../common/WPropertyHelper.h"
#include "../common/math/WMatrix4x4.h"
#include "../common/math/WMatrix.h"
#include "WGETextureUtils.h"
......@@ -428,7 +428,8 @@ void WGETexture< TextureType >::setupProperties( double scale, double min )
m_active = m_properties->addProperty( "Active", "Can dis-enable a texture.", true );
m_texMatrix = m_properties->addProperty( "Texture Transformation", "Usable to transform the texture.", osg::Matrix::identity() );
WMatrix4x4_2 m = WMatrix4x4_2::Identity();
m_texMatrix = m_properties->addProperty( "Texture Transformation", "Usable to transform the texture.", m );
m_texMatrix->setPurpose( PV_PURPOSE_INFORMATION );
TextureType::setResizeNonPowerOfTwoHint( false );
......
......@@ -38,6 +38,7 @@
#include "shaders/WGEPropertyUniform.h"
#include "callbacks/WGEPropertyTransformationCallback.h"
#include "../common/math/WMatrix.h"
#include "WExportWGE.h"
......@@ -171,7 +172,7 @@ 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
osg::TexMat* texMat = new osg::TexMat( texture->transformation()->get() );
osg::TexMat* texMat = new osg::TexMat( toOsgMatrixd( texture->transformation()->get() ) );
// use a callback to update the tex matrix if needed according to transformation property of texture
texMat->setUpdateCallback( new WGEPropertyTransformationCallback< osg::StateAttribute, osg::TexMat >( texture->transformation() ) );
node->getOrCreateStateSet()->setTextureAttributeAndModes( unit, texMat, osg::StateAttribute::ON );
......
......@@ -32,6 +32,7 @@
#include "WGECallbackTraits.h"
#include "../../common/WProperties.h"
#include "../../common/math/WMatrix.h"
#include "../WExportWGE.h"
/**
......@@ -93,7 +94,7 @@ void WGEPropertyTransformationCallback< ParentType, TargetType >::operator()( ty
TargetType* m = dynamic_cast< TargetType* >( handled );
if ( m )
{
m->setMatrix( m_prop->get() );
m->setMatrix( toOsgMatrixd( m_prop->get() ) );
}
WGECallbackTraits< ParentType >::traverse( this, handled, nv );
......
......@@ -27,6 +27,7 @@
#include <osg/LineWidth>
#include "../callbacks/WGEFunctorCallback.h"
#include "../../common/math/WMatrix.h"
#include "../WGEGeodeUtils.h"
#include "WGEGridNode.h"
......@@ -215,7 +216,7 @@ void WGEGridNode::callback( osg::Node* /*node*/ )
// apply the grid transformation
osg::Matrix m = osg::Matrix::scale( grid->getNbCoordsX() - 1, grid->getNbCoordsY() - 1, grid->getNbCoordsZ() - 1 ) *
grid->getTransform();
toOsgMatrixd( grid->getTransform() );
setMatrix( m );
// set the labels correspondingly
......
......@@ -95,7 +95,7 @@ void WPropertyMatrix4X4Widget::update()
}
// do not forget to update the label
m_asText.setText( QString::fromStdString( toString( m_matrixProperty->get() ) ) );
m_asText.setText( QString::fromStdString( boost::lexical_cast< std::string >( m_matrixProperty->get() ) ) );
}
void WPropertyMatrix4X4Widget::editChanged()
......
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