30 #include "../common/WLogger.h"
31 #include "../common/WStringUtils.h"
33 #include "WGETextureUtils.h"
34 #include "exceptions/WGESignalSubscriptionFailed.h"
36 #include "WGEColormapping.h"
47 void setDefines( osg::ref_ptr< WGEShader > shader,
size_t start = 0 )
68 void setPreTransform( osg::ref_ptr< WGEShader > shader, osg::Matrixd preTransform )
70 std::ostringstream out;
72 const osg::Matrixd::value_type* m = preTransform.ptr();
75 out.setf( std::ios::fixed, std::ios::floatfield );
78 for(
size_t i = 0; i < 15; ++i )
80 out << m[ i ] <<
", ";
82 out << m[ 15 ] <<
" )";
85 shader->setDefine(
"ColormapPreTransform", out.str() );
92 m_boundingBox.getWriteTicket()->get().set( 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 );
116 size_t startTexUnit )
118 instance()->applyInst(
NodeList( 1, node ), preTransform, shader, startTexUnit );
123 instance()->applyInst( nodes, preTransform, shader, startTexUnit );
133 instance()->registerTextureInst( texture, name );
138 instance()->deregisterTextureInst( texture );
143 instance()->replaceTextureInst( old, newTex, name );
147 size_t startTexUnit )
150 osg::ref_ptr< WGEShader > s = shader;
154 s =
new WGEShader(
"WGEDefaultColormapper" );
156 setDefines( s, startTexUnit );
157 setPreTransform( s, preTransform );
160 for( NodeList::const_iterator i = nodes.begin(); i != nodes.end(); ++i )
178 wlog::debug(
"WGEColormapping" ) <<
"Registering texture \"" << name <<
"\".";
183 texture->name()->set( name );
193 wlog::debug(
"WGEColormapping" ) <<
"De-registering texture \"" << texture->name()->get() <<
"\".";
204 wlog::debug(
"WGEColormapping" ) <<
"Replacing texture.";
207 newTex->name()->set( name );
233 bbw->get() = ( *iter )->getBoundingBox();
238 bbw->get().expandBy( ( *iter )->getBoundingBox() );
253 iter->second->m_rebind =
true;
265 bool sortIndexComparator( osg::ref_ptr< WGETexture3D > a, osg::ref_ptr< WGETexture3D > b )
267 return ( a->sortIndex()->get() < b->sortIndex()->get() );
282 ( *iter )->sortIndex()->set( index );
301 if( infoItem == r->get().end() )
322 ( unit < maxTexUnits ) && ( iter != rt->get().end() );
339 if( iter == w->get().end() )
345 if( iter + 1 == w->get().end() )
351 std::iter_swap( iter, iter + 1 );
366 if( iter == w->get().end() )
372 if( iter == w->get().begin() )
378 std::iter_swap( iter, iter - 1 );
393 if( iter == w->get().end() )
399 if( iter == w->get().begin() )
405 w->get().erase( iter );
406 w->get().insert( w->get().begin(), texture );
421 if( iter == w->get().end() )
427 if( iter + 1 == w->get().end() )
433 w->get().erase( iter );
434 w->get().push_back( texture );
449 if( iter == w->get().end() )
456 if( idx > w->get().size() )
462 if( iter == ( w->get().begin() + idx ) )
468 size_t eraseIdx = iter - w->get().begin();
469 size_t eraseShift = 0;
471 if( ( w->get().begin() + idx ) < iter )
479 w->get().insert( w->get().begin() + idx, texture );
480 w->get().erase( w->get().begin() + eraseIdx + eraseShift );
boost::shared_ptr< WSharedObjectTicketWrite< T > > WriteTicket
Type for write tickets.
bool moveUp(osg::ref_ptr< WGETexture3D > texture)
Move the specified texture one item up in the list.
TextureContainerType m_textures
The textures managed by this instance.
WGEColormapping()
Default constructor.
static void registerTexture(osg::ref_ptr< WGETexture3D > texture, std::string name="")
Register the specified texture to the colormapper.
size_t size() const
Counts the number of textures in the colormapper.
static WPVBaseTypes::PV_INT getUnsetSortIndex()
Get the index used to refer to an unset sort index.
std::pair< Iterator, bool > insert(const value_type &x)
Inserts the specified element.
boost::function< void(void) > TextureSortHandler
The type of handler called whenever the texture list got resorted.
void deregisterTextureInst(osg::ref_ptr< WGETexture3D > texture)
De-register the specified texture to the colormapper.
size_t size() const
The size of the container.
size_t m_texUnitStart
the start index of the texture unit to use
static void deregisterTexture(osg::ref_ptr< WGETexture3D > texture)
De-register the specified texture to the colormapper.
boost::function< void(osg::ref_ptr< WGETexture3D >, osg::ref_ptr< WGETexture3D >) > TextureReplaceHandler
The type of handler used for being notified about replaced textures.
void stableSort(Comparator comp)
Resorts the texture list using the specified comparator using a stable sorting algorithm.
This callback allows you a simple usage of callbacks in your module.
std::map< osg::Node *, NodeInfo *, std::less< osg::Node * > >::const_iterator ConstIterator
A typedef for the correct const iterator useful to traverse this sequence container.
void sortByIndex()
Sort the texture list by the indices that have been stored in each texture's sortIndex.
void registerTextureInst(osg::ref_ptr< WGETexture3D > texture, std::string name)
Register the specified texture to the colormapper.
void callback(osg::Node *node)
This callback handles all the updates needed.
boost::signals2::connection subscribeSignal(TextureListSignal signal, TextureRegisterHandler notifier)
Subscribe to the specified signal.
WCondition::SPtr getChangeCondition() const
Returns the condition firing if the texture list changes (sort, replace, add or remove).
NodeInfoContainerType m_nodeInfo
This map is needed to keep track of several node specific settings.
ReadTicket getReadTicket() const
Returns a ticket to get read access to the contained data.
Represents a axis parallel bounding box and provides some useful operations with them.
WSharedObject< WBoundingBox > m_boundingBox
The bounding box of all the textures.
std::map< osg::Node *, NodeInfo *, std::less< osg::Node * > >::iterator Iterator
A typedef for the correct iterator to traverse this sequence container.
WriteTicket getWriteTicket(bool suppressNotify=false) const
Returns a ticket to get write access to the contained data.
std::vector< osg::ref_ptr< WGETexture3D > >::const_iterator ConstIterator
A typedef for the correct const iterator useful to traverse this sequence container.
Exception thrown if a notifier could not be subscribed to a signal.
void replace(const typename S::value_type &oldValue, const typename S::value_type &newValue)
Replaces the specified old value by a new one.
boost::signals2::signal< void(void) > m_sortSignal
Called whenever the texture list got resorted.
Simple structure to store some additional node-related info like texture units and so on...
texture list was resorted
Class encapsulating the OSG Program class for a more convenient way of adding and modifying shader...
boost::signals2::signal< void(osg::ref_ptr< WGETexture3D >) > m_deregisterSignal
Called whenever a texture got removed.
bool moveDown(osg::ref_ptr< WGETexture3D > texture)
Move the specified texture one item down in the list.
void remove(const typename S::value_type &element)
Searches and removes the specified element.
virtual ~WGEColormapping()
Destructor.
static void replaceTexture(osg::ref_ptr< WGETexture3D > old, osg::ref_ptr< WGETexture3D > newTex, std::string name="")
Replaces the specified texture with the given new one.
WMatrix4d m_preTransform
matrix used for transforming arbitrary texture coordinates to the proper space.
void textureUpdate()
Called whenever the texture list is updated.
TextureContainerType::ReadTicket getReadTicket()
Returns a read ticket to the texture array.
static boost::shared_ptr< WGEColormapping > instance()
Returns instance of the module factory to use to create modules.
void unbindTexture(osg::ref_ptr< osg::Node > node, size_t unit, size_t count=1)
Removes the binding associated with the specified unit.
std::string toString(const T &value)
Convert a given value to a string.
static MatrixType identity()
Returns an identity matrix.
bool m_rebind
true if the node has not been callback'ed before
WBoundingBox getBoundingBox() const
This returns the bounding box of all the data textures.
boost::signals2::signal< void(osg::ref_ptr< WGETexture3D >, osg::ref_ptr< WGETexture3D >) > m_replaceSignal
Called whenever a texture got replaced.
bool moveToTop(osg::ref_ptr< WGETexture3D > texture)
Move the specified texture up in the list, directly to the top.
void resetSortIndices()
Reset all sort indices.
std::vector< osg::ref_ptr< osg::Node > > NodeList
a bunch of nodes.
void setSortIndices()
This function sets the index of a texture in the list to this texture's WGETexture::sortIndex().
void replaceTextureInst(osg::ref_ptr< WGETexture3D > old, osg::ref_ptr< WGETexture3D > newTex, std::string name="")
Replaces the specified texture with the given new one.
static void apply(osg::ref_ptr< osg::Node > node, WMatrix4d preTransform=WMatrix4d::identity(), osg::ref_ptr< WGEShader > shader=osg::ref_ptr< WGEShader >(), size_t startTexUnit=0)
Apply the colormapping to the specified node.
void updateBounds()
Updates the bounding box information.
size_t getMaxTexUnits()
Returns the maximum number of textures that can be bound to a node.
void bindTexture(osg::ref_ptr< osg::Node > node, osg::ref_ptr< WDataTexture3D > texture, size_t unit=0, std::string prefix="")
Binds the specified texture to the specified unit.
boost::function< void(osg::ref_ptr< WGETexture3D >) > TextureRegisterHandler
The type of handler used for being notified about added textures.
void push_front(const typename S::value_type &x)
Adds a new element at the beginning of the container.
boost::shared_ptr< WCondition > SPtr
Shared pointer type for WCondition.
void applyInst(NodeList nodes, WMatrix4d preTransform=WMatrix4d::identity(), osg::ref_ptr< WGEShader > shader=osg::ref_ptr< WGEShader >(), size_t startTexUnit=0)
Apply the colormapping to the specified nodes.
WStreamedLogger debug(const std::string &source)
Logging a debug message.
std::vector< osg::ref_ptr< WGETexture3D > >::iterator Iterator
A typedef for the correct iterator to traverse this sequence container.
boost::shared_ptr< WSharedObjectTicketRead< std::vector< osg::ref_ptr< WGETexture3D > > > > ReadTicket
Type for read tickets.
static boost::shared_ptr< WGEColormapping > m_instance
Singleton instance of WGEColormapping.
bool moveToBottom(osg::ref_ptr< WGETexture3D > texture)
Move the specified texture down in the list, directly to the bottom.
bool moveTo(osg::ref_ptr< WGETexture3D > texture, size_t idx)
Move the texture to the specified index.
size_t count(const value_type &value)
Counts the number of occurrences of the specified value inside the container.
boost::shared_ptr< WCondition > getChangeCondition() const
This condition fires whenever the encapsulated object changed.
boost::signals2::signal< void(osg::ref_ptr< WGETexture3D >) > m_registerSignal
Called whenever a texture got registered.
TextureListSignal
Possible signals that can be subscribed for being notified about texture list changes.