Commit 04e3f7bf authored by Sebastian Eichelbaum's avatar Sebastian Eichelbaum
Browse files

[ADD #259] created infrastructure to save colormap ordering. Some questions are still open.

parent 2e952816
......@@ -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
sort( &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,22 @@ public:
template < typename Comparator >
void sort( 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.
*
......
......@@ -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
{
......
......@@ -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
WModuleContainer::ModuleSharedContainerType::ReadTicket container = WKernel::getRunningKernel()->getRootContainer()->getModules();
......
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