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

[MERGE]

parents 93214bba fdc07bd7
......@@ -213,6 +213,26 @@ public:
template < typename Comparator >
void sort( typename WSharedSequenceContainer< S >::Iterator first, typename WSharedSequenceContainer< S >::Iterator last, Comparator comp );
/**
* Resorts the container using the specified comparator from its begin to its end. Uses stable sort algorithm.
*
* \tparam Comparator the comparator type. Usually a boost::function or class providing the operator().
*
* \param comp the comparator
*/
template < typename Comparator >
void stableSort( Comparator comp );
/**
* Resorts the container using the specified comparator between [first,last) in ascending order. Uses stable sort algorithm.
*
* \param first the first element
* \param last the last element
* \param comp the comparator
*/
template < typename Comparator >
void stableSort( typename WSharedSequenceContainer< S >::Iterator first, typename WSharedSequenceContainer< S >::Iterator last, Comparator comp );
/**
* Searches the specified value in the range [first,last).
*
......@@ -380,6 +400,23 @@ void WSharedSequenceContainer< S >::sort( typename WSharedSequenceContainer< S >
return std::sort( first, last, comp );
}
template < typename S >
template < typename Comparator >
void WSharedSequenceContainer< S >::stableSort( Comparator comp )
{
typename WSharedObject< S >::WriteTicket a = WSharedObject< S >::getWriteTicket();
return std::stable_sort( a->get().begin(), a->get().end(), comp );
}
template < typename S >
template < typename Comparator >
void WSharedSequenceContainer< S >::stableSort( typename WSharedSequenceContainer< S >::Iterator first,
typename WSharedSequenceContainer< S >::Iterator last,
Comparator comp )
{
return std::stable_sort( first, last, comp );
}
template < typename S >
typename WSharedSequenceContainer< S >::Iterator WSharedSequenceContainer< S >::find(
typename WSharedSequenceContainer< S >::Iterator first,
......
......@@ -156,6 +156,21 @@ T factorial( T i )
return res;
}
/**
* Checks if two values are equal within a given delta.
*
* \tparam The floating point type.
* \param a The first value.
* \param b The second value.
* \param delta The tolerance parameter.
* \return True if both values are equal within the delta, otherwise false.
*/
template< typename T >
T areEqual( T a, T b, T delta = T( 0 ) )
{
return ( std::fabs( a - b ) <= delta );
}
template< typename T > inline int signum( const T& value )
{
if( value < 0 )
......
......@@ -195,6 +195,19 @@ public:
}
}
/**
* Returns true if the matrix is a square matrix.
* \return true for square matrixes, otherwise false.
*/
bool isSquare() const;
/**
* Returns true if the matrix is a identity matrix.
* \param delta - tolerance parameter when checking the values.
* \return true for identity matrixes, otherwise false.
*/
bool isIdentity( T delta = T( 0.0 ) ) const;
protected:
private:
size_t m_nbCols; //!< Number of columns of the matrix. The number of rows will be computed by (size/m_nbCols).
......@@ -454,6 +467,33 @@ template< typename T > WVector3d WMatrix< T >::operator*( const WVector3d& rhs )
return result;
}
template< typename T > bool WMatrix< T >::isSquare() const
{
return getNbRows() == getNbCols();
}
template< typename T > bool WMatrix< T >::isIdentity( T delta ) const
{
if( !isSquare() )
{
return false;
}
for( size_t row = 0; row < getNbRows(); row++ )
{
for( size_t col = 0; col < getNbCols(); col++ )
{
T val = ( *this )( row, col );
T expected = ( row == col ? T( 1.0 ) : T( 0.0 ) );
if( std::fabs( val - expected ) > delta )
{
return false;
}
}
}
return true;
}
template< typename T >
inline std::ostream& operator<<( std::ostream& os, const WMatrix< T >& m )
{
......
......@@ -152,7 +152,7 @@ double WSymmetricSphericalHarmonic::calcGFA( std::vector< WUnitSphereCoordinates
double d = 0.0;
double gfa = 0.0;
double mean = 0.0;
double v[ 15 ];
std::vector< double > v( orientations.size() );
for( std::size_t i = 0; i < orientations.size(); ++i )
{
......@@ -513,6 +513,8 @@ WMatrix< double > WSymmetricSphericalHarmonic::calcSHToTensorSymMatrix( std::siz
WMatrix< double > p = pseudoInverse( TEMat );
WAssert( ( TEMat*p ).isIdentity( 1e-3 ), "Test of inverse matrix failed. Are the given orientations linear independent?" );
return p * calcBaseMatrix( ori2, order );
}
......
......@@ -124,7 +124,7 @@ public:
*
* \return The function value on the sphere for this tensor and the given gradient.
*/
Data_T evaluateSphericalFunction( WVector3d const& gradient ) const;
Data_T evaluateSphericalFunction( WMatrixFixed< Data_T, 3, 1 > const& gradient ) const;
protected:
private:
......@@ -158,7 +158,7 @@ Data_T WTensorSym< order, dim, Data_T >::evaluateSphericalFunction( WValue< Data
}
template< std::size_t order, std::size_t dim, typename Data_T >
Data_T WTensorSym< order, dim, Data_T >::evaluateSphericalFunction( WVector3d const& gradient ) const
Data_T WTensorSym< order, dim, Data_T >::evaluateSphericalFunction( WMatrixFixed< Data_T, 3, 1 > const& gradient ) const
{
Data_T const* tens = &m_data[ 0 ];
Data_T const* grad = &gradient[ 0 ];
......
......@@ -265,6 +265,18 @@ public:
TS_ASSERT_EQUALS( factorial( 7 ), 5040 );
TS_ASSERT_EQUALS( factorial( 8 ), 40320 );
}
/**
* Test the areEqual function.
*/
void testAreEqual( void )
{
TS_ASSERT_EQUALS( areEqual( 1.0, 1.0 ), true );
TS_ASSERT_EQUALS( areEqual( 1.0, 1.0, 1e-3 ), true );
TS_ASSERT_EQUALS( areEqual( 1.0, 1.0+1e-3, 1e-3 ), true );
TS_ASSERT_EQUALS( areEqual( 1.0, 1.0+2e-3, 1e-3 ), false );
TS_ASSERT_EQUALS( areEqual( 1.0, 1.0+1e-3 ), false );
}
};
#endif // WMATH_TEST_H
......@@ -247,6 +247,28 @@ public:
for( size_t col = 0; col < nbCols; col++ )
TS_ASSERT_EQUALS( matrixTransposed( col, row ), ( row+1 )*10 + col + 1 );
}
/**
* Test isIdentity method of WMatrix
*/
void testIsIdentity( void )
{
WMatrix< double > a( 3, 2 );
a.makeIdentity();
TS_ASSERT_EQUALS( a.isIdentity(), false );
WMatrix< double > b( 3, 3 );
b.makeIdentity();
TS_ASSERT_EQUALS( b.isIdentity(), true );
b( 0, 0 ) += 1e-3;
TS_ASSERT_EQUALS( b.isIdentity(), false );
TS_ASSERT_EQUALS( b.isIdentity( 1e-3 ), true );
b( 0, 1 ) += 2e-3;
TS_ASSERT_EQUALS( b.isIdentity( 1e-3 ), false );
TS_ASSERT_EQUALS( b.isIdentity( 2e-3 ), true );
}
};
#endif // WMATRIX_TEST_H
......@@ -175,7 +175,7 @@ void WGEColormapping::applyInst( NodeList nodes, WMatrix4d preTransform, osg::re
void WGEColormapping::registerTextureInst( osg::ref_ptr< WGETexture3D > texture, std::string name )
{
wlog::debug( "WGEColormapping" ) << "Registering texture.";
wlog::debug( "WGEColormapping" ) << "Registering texture \"" << name << "\".";
if( !m_textures.count( texture ) )
{
if( !name.empty() )
......@@ -190,7 +190,7 @@ void WGEColormapping::registerTextureInst( osg::ref_ptr< WGETexture3D > texture,
void WGEColormapping::deregisterTextureInst( osg::ref_ptr< WGETexture3D > texture )
{
wlog::debug( "WGEColormapping" ) << "De-registering texture.";
wlog::debug( "WGEColormapping" ) << "De-registering texture \"" << texture->name()->get() << "\".";
if( m_textures.count( texture ) )
{
m_textures.remove( texture );
......@@ -254,6 +254,45 @@ void WGEColormapping::textureUpdate()
}
}
/**
* Custom comparator which uses a textures sortIndex for comparing.
*
* \param a first element
* \param b second element
*
* \return true if a's sortIndex is smaller than b's.
*/
bool sortIndexComparator( osg::ref_ptr< WGETexture3D > a, osg::ref_ptr< WGETexture3D > b )
{
return ( a->sortIndex()->get() < b->sortIndex()->get() );
}
void WGEColormapping::sortByIndex()
{
// use sort with custom comparator
stableSort( &sortIndexComparator );
}
void WGEColormapping::setSortIndices()
{
TextureContainerType::ReadTicket r = m_textures.getReadTicket();
size_t index = 0;
for( TextureContainerType::ConstIterator iter = r->get().begin(); iter != r->get().end(); ++iter )
{
( *iter )->sortIndex()->set( index );
index++;
}
}
void WGEColormapping::resetSortIndices()
{
TextureContainerType::ReadTicket r = m_textures.getReadTicket();
for( TextureContainerType::ConstIterator iter = r->get().begin(); iter != r->get().end(); ++iter )
{
( *iter )->sortIndex()->set( 0 );
}
}
void WGEColormapping::callback( osg::Node* node )
{
// get node info
......
......@@ -190,6 +190,31 @@ public:
template < typename Comparator >
void sort( Comparator comp );
/**
* Resorts the texture list using the specified comparator using a stable sorting algorithm.
*
* \tparam Comparator the comparator type. Usually a boost::function or class providing the operator().
* \param comp the comparator
*/
template < typename Comparator >
void stableSort( Comparator comp );
/**
* Sort the texture list by the indices that have been stored in each texture's sortIndex.
*/
void sortByIndex();
/**
* This function sets the index of a texture in the list to this texture's WGETexture::sortIndex(). This can be used later using
* sortByIndex().
*/
void setSortIndices();
/**
* Reset all sort indices. This can be useful when loading new project files with new sort indices.
*/
void resetSortIndices();
/**
* Move the specified texture up in the list, directly to the top. Causes the sort signal to fire.
*
......@@ -430,5 +455,11 @@ void WGEColormapping::sort( Comparator comp )
m_textures.sort< Comparator >( comp );
}
template < typename Comparator >
void WGEColormapping::stableSort( Comparator comp )
{
m_textures.stableSort< Comparator >( comp );
}
#endif // WGECOLORMAPPING_H
......@@ -95,6 +95,13 @@ public:
*/
WPropString name() const;
/**
* The sorting index in the colormapper's texture list.
*
* \return the property.
*/
WPropInt sortIndex() const;
/**
* Get the minimum in the de-scaled value space. The property can be changed. A change affects all colormaps using this texture. But be
* careful as the texture creating depends on these values.
......@@ -330,6 +337,11 @@ private:
*/
WPropString m_name;
/**
* The sort index of the texture. This is important for restoring and saving the colormapper's sorting.
*/
WPropInt m_sortIdx;
/**
* The minimum of each value in the texture in unscaled space.
*/
......@@ -458,6 +470,11 @@ void WGETexture< TextureType >::setupProperties( double scale, double min )
m_name = m_properties->addProperty( "Name", "The name of the texture.", std::string( "Unnamed" ) );
m_sortIdx = m_properties->addProperty( "Sort Index",
"The index specifies the index in the colormapper, used to restore colormapper sorting on load.",
-1 );
m_sortIdx->setHidden( true );
// initialize members
m_min = m_properties->addProperty( "Minimum", "The minimum value in the original space.", min, true );
m_min->removeConstraint( m_min->getMin() );
......@@ -543,6 +560,12 @@ inline WPropString WGETexture< TextureType >::name() const
return m_name;
}
template < typename TextureType >
inline WPropInt WGETexture< TextureType >::sortIndex() const
{
return m_sortIdx;
}
template < typename TextureType >
inline WPropDouble WGETexture< TextureType >::minimum() const
{
......
......@@ -23,6 +23,7 @@
//---------------------------------------------------------------------------
#include <list>
#include <string>
#include "WROI.h"
#include "WPickHandler.h"
......@@ -41,15 +42,33 @@ void WROI::properties()
{
m_properties = boost::shared_ptr< WProperties >( new WProperties( "Properties", "This ROI's properties" ) );
m_active = m_properties->addProperty( "active", "", true, boost::bind( &WROI::propertyChanged, this ) );
m_active->setHidden( true );
m_show = m_properties->addProperty( "Show", "Toggles visibility of the roi", true, boost::bind( &WROI::propertyChanged, this ) );
m_name = m_properties->addProperty( "Name", "The name of this ROI.", std::string( "ROI" ) );
m_active = m_properties->addProperty( "Active", "Enable or disable the ROI.", true, boost::bind( &WROI::propertyChanged, this ) );
m_show = m_properties->addProperty( "Show", "Toggles visibility of the ROI but does not disable it.", true,
boost::bind( &WROI::propertyChanged, this ) );
m_not = m_properties->addProperty( "Not", "Negates the effect of this ROI.", false, boost::bind( &WROI::propertyChanged, this ) );
m_dirty = m_properties->addProperty( "Dirty", "", true ); // boost::bind( &WROI::propertyChanged, this ) );
m_dirty->setHidden( true );
}
m_not = m_properties->addProperty( "Not", "Negates the effect of this ROI.", false, boost::bind( &WROI::propertyChanged, this ) );
WPropBool WROI::invertProperty()
{
return m_not;
}
WPropBool WROI::showProperty()
{
return m_show;
}
WPropString WROI::nameProperty()
{
return m_name;
}
WPropBool WROI::activeProperty()
{
return m_active;
}
void WROI::propertyChanged()
......
......@@ -35,9 +35,6 @@
#include "../common/WProperties.h"
class WPickHandler;
/**
......@@ -122,7 +119,33 @@ public:
*/
void removeROIChangeNotifier( boost::shared_ptr< boost::function< void() > > notifier );
/**
* Invert property.
*
* \return the property
*/
WPropBool invertProperty();
/**
* The property for toggling ROI visibility.
*
* \return the property
*/
WPropBool showProperty();
/**
* The active property
*
* \return the property.
*/
WPropBool activeProperty();
/**
* The name property
*
* \return the property.
*/
WPropString nameProperty();
protected:
/**
* initializes the roi's properties
......@@ -168,6 +191,11 @@ protected:
*/
WPropBool m_not;
/**
* name of the ROI.
*/
WPropString m_name;
/**
* threshold for an arbitrary roi
*/
......
......@@ -24,7 +24,8 @@
#include "WDataModule.h"
WDataModule::WDataModule()
WDataModule::WDataModule():
m_suppressColormaps( false )
{
// initialize members
}
......
......@@ -23,6 +23,7 @@
//---------------------------------------------------------------------------
#include <list>
#include <string>
#include <vector>
#include "../graphicsEngine/WGraphicsEngine.h"
......@@ -47,9 +48,11 @@ void WRMBranch::properties()
m_dirty = m_properties->addProperty( "Dirty", "", true, boost::bind( &WRMBranch::propertyChanged, this ) );
m_dirty->setHidden( true );
m_name = m_properties->addProperty( "Name", "The name of this branch.", std::string( "Branch" ) );
m_isNot = m_properties->addProperty( "Not", "Negate the effect of this branch.", false, boost::bind( &WRMBranch::propertyChanged, this ) );
m_bundleColor = m_properties->addProperty( "Bundle color", "", WColor( 1.0, 0.0, 0.0, 1.0 ),
m_bundleColor = m_properties->addProperty( "Bundle color", "Color the selected fibers using this color.", WColor( 1.0, 0.0, 0.0, 1.0 ),
boost::bind( &WRMBranch::propertyChanged, this ) );
m_changeRoiSignal = boost::shared_ptr< boost::function< void() > >( new boost::function< void() >( boost::bind( &WRMBranch::setDirty, this ) ) );
}
......@@ -58,6 +61,20 @@ void WRMBranch::propertyChanged()
setDirty();
}
WPropString WRMBranch::nameProperty()
{
return m_name;
}
WPropBool WRMBranch::invertProperty()
{
return m_isNot;
}
WPropColor WRMBranch::colorProperty()
{
return m_bundleColor;
}
void WRMBranch::addRoi( osg::ref_ptr< WROI > roi )
{
......
......@@ -56,6 +56,27 @@ public:
*/
~WRMBranch();
/**
* Get name property.
*
* \return name property
*/
WPropString nameProperty();
/**
* Get the "not" property.
*
* \return the property
*/
WPropBool invertProperty();
/**
* The branch color property.
*
* \return the color property
*/
WPropColor colorProperty();
/**
* adds a roi to the branch
*
......@@ -185,6 +206,11 @@ private:
*/
WPropColor m_bundleColor;
/**
* Name property.
*/
WPropString m_name;
/**
* The notifiers connected to added rois by default.
*/
......
......@@ -50,6 +50,8 @@
#include "../../common/WLogger.h"
#include "../../common/math/linearAlgebra/WLinearAlgebra.h"
#include "../../graphicsEngine/WGEColormapping.h"
#include "WModuleProjectFileCombiner.h"
WModuleProjectFileCombiner::WModuleProjectFileCombiner( boost::shared_ptr< WModuleContainer > target ):
......@@ -173,6 +175,9 @@ bool WModuleProjectFileCombiner::parse( std::string line, unsigned int lineNumbe
void WModuleProjectFileCombiner::apply()
{
// reset sort indices in colormapper as we load new ones.
WGEColormapping::instance()->resetSortIndices();
// now add each module to the target container
for( std::map< unsigned int, boost::shared_ptr< WModule > >::const_iterator iter = m_modules.begin(); iter != m_modules.end(); ++iter )
{
......@@ -301,6 +306,9 @@ void WModuleProjectFileCombiner::apply()
}
}
// the colornapper should now sort the textures according to the loaded indices
WGEColormapping::instance()->sortByIndex();
// notify modules about the loaded set properties
for( std::map< unsigned int, boost::shared_ptr< WModule > >::iterator iter = m_modules.begin(); iter != m_modules.end(); ++iter )
{
......@@ -358,6 +366,9 @@ void WModuleProjectFileCombiner::printProperties( std::ostream& output, boost::s
void WModuleProjectFileCombiner::save( std::ostream& output ) // NOLINT
{
// we need to save the colormapper's texture order. To do this, we need to update the textures sort indices
WGEColormapping::instance()->setSortIndices();
// grab access object of root container