31 #include "../common/WLogger.h"
32 #include "../common/WStringUtils.h"
33 #include "WGEColormapping.h"
34 #include "WGETextureUtils.h"
35 #include "exceptions/WGESignalSubscriptionFailed.h"
46 void setDefines( osg::ref_ptr< WGEShader > shader,
size_t start = 0 )
67 void setPreTransform( osg::ref_ptr< WGEShader > shader, osg::Matrixd preTransform )
69 std::ostringstream out;
71 const osg::Matrixd::value_type* m = preTransform.ptr();
74 out.setf( std::ios::fixed, std::ios::floatfield );
77 for(
size_t i = 0; i < 15; ++i )
79 out << m[ i ] <<
", ";
81 out << m[ 15 ] <<
" )";
84 shader->setDefine(
"ColormapPreTransform", out.str() );
91 m_boundingBox.getWriteTicket()->get().set( 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 );
115 size_t startTexUnit )
117 instance()->applyInst(
NodeList( 1, node ), preTransform, shader, startTexUnit );
122 instance()->applyInst( nodes, preTransform, shader, startTexUnit );
132 instance()->registerTextureInst( texture, name );
137 instance()->deregisterTextureInst( texture );
142 instance()->replaceTextureInst( old, newTex, name );
146 size_t startTexUnit )
149 osg::ref_ptr< WGEShader > s = shader;
153 s =
new WGEShader(
"WGEDefaultColormapper" );
155 setDefines( s, startTexUnit );
156 setPreTransform( s, preTransform );
159 for( NodeList::const_iterator i = nodes.begin(); i != nodes.end(); ++i )
163 info->m_rebind =
true;
164 info->m_texUnitStart = startTexUnit;
165 info->m_preTransform = preTransform;
177 wlog::debug(
"WGEColormapping" ) <<
"Registering texture \"" << name <<
"\".";
182 texture->name()->set( name );
192 wlog::debug(
"WGEColormapping" ) <<
"De-registering texture \"" << texture->name()->get() <<
"\".";
203 wlog::debug(
"WGEColormapping" ) <<
"Replacing texture.";
206 newTex->name()->set( name );
232 bbw->get() = ( *iter )->getBoundingBox();
237 bbw->get().expandBy( ( *iter )->getBoundingBox() );
252 iter->second->m_rebind =
true;
264 bool sortIndexComparator( osg::ref_ptr< WGETexture3D > a, osg::ref_ptr< WGETexture3D > b )
266 return ( a->sortIndex()->get() < b->sortIndex()->get() );
281 ( *iter )->sortIndex()->set( index );
300 if( infoItem == r->get().end() )
311 info->m_rebind =
false;
319 size_t unit = info->m_texUnitStart;
321 ( unit < maxTexUnits ) && ( iter != rt->get().end() );
338 if( iter == w->get().end() )
344 if( iter + 1 == w->get().end() )
350 std::iter_swap( iter, iter + 1 );
365 if( iter == w->get().end() )
371 if( iter == w->get().begin() )
377 std::iter_swap( iter, iter - 1 );
392 if( iter == w->get().end() )
398 if( iter == w->get().begin() )
404 w->get().erase( iter );
405 w->get().insert( w->get().begin(), texture );
420 if( iter == w->get().end() )
426 if( iter + 1 == w->get().end() )
432 w->get().erase( iter );
433 w->get().push_back( texture );
448 if( iter == w->get().end() )
455 if( idx > w->get().size() )
461 if( iter == ( w->get().begin() + idx ) )
467 size_t eraseIdx = iter - w->get().begin();
468 size_t eraseShift = 0;
470 if( ( w->get().begin() + idx ) < iter )
478 w->get().insert( w->get().begin() + idx, texture );
479 w->get().erase( w->get().begin() + eraseIdx + eraseShift );
std::shared_ptr< WCondition > SPtr
Shared pointer type for WCondition.
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.
void sortByIndex()
Sort the texture list by the indices that have been stored in each texture's sortIndex.
void textureUpdate()
Called whenever the texture list is updated.
boost::function< void(void) > TextureSortHandler
The type of handler called whenever the texture list got resorted.
boost::function< void(osg::ref_ptr< WGETexture3D >, osg::ref_ptr< WGETexture3D >) > TextureReplaceHandler
The type of handler used for being notified about replaced textures.
WBoundingBox getBoundingBox() const
This returns the bounding box of all the data textures.
void setSortIndices()
This function sets the index of a texture in the list to this texture's WGETexture::sortIndex().
void registerTextureInst(osg::ref_ptr< WGETexture3D > texture, std::string name)
Register the specified texture to the colormapper.
void stableSort(Comparator comp)
Resorts the texture list using the specified comparator using a stable sorting algorithm.
WCondition::SPtr getChangeCondition() const
Returns the condition firing if the texture list changes (sort, replace, add or remove).
TextureContainerType m_textures
The textures managed by this instance.
WSharedObject< WBoundingBox > m_boundingBox
The bounding box of all the textures.
static void registerTexture(osg::ref_ptr< WGETexture3D > texture, std::string name="")
Register the specified texture to the colormapper.
WGEColormapping()
Default constructor.
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.
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.
TextureContainerType::ReadTicket getReadTicket()
Returns a read ticket to the texture array.
void callback(osg::Node *node)
This callback handles all the updates needed.
size_t size() const
Counts the number of textures in the colormapper.
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.
boost::signals2::signal< void(void) > m_sortSignal
Called whenever the texture list got resorted.
static std::shared_ptr< WGEColormapping > instance()
Returns instance of the module factory to use to create modules.
virtual ~WGEColormapping()
Destructor.
bool moveTo(osg::ref_ptr< WGETexture3D > texture, size_t idx)
Move the texture to the specified index.
TextureListSignal
Possible signals that can be subscribed for being notified about texture list changes.
@ Deregistered
texture got removed
@ Registered
texture got added
@ Sorted
texture list was resorted
@ Replaced
texture got replaced
static void deregisterTexture(osg::ref_ptr< WGETexture3D > texture)
De-register the specified texture to the colormapper.
static std::shared_ptr< WGEColormapping > m_instance
Singleton instance of WGEColormapping.
boost::function< void(osg::ref_ptr< WGETexture3D >) > TextureRegisterHandler
The type of handler used for being notified about added textures.
boost::signals2::signal< void(osg::ref_ptr< WGETexture3D >) > m_deregisterSignal
Called whenever a texture got removed.
void updateBounds()
Updates the bounding box information.
void replaceTextureInst(osg::ref_ptr< WGETexture3D > old, osg::ref_ptr< WGETexture3D > newTex, std::string name="")
Replaces the specified texture with the given new one.
void deregisterTextureInst(osg::ref_ptr< WGETexture3D > texture)
De-register the specified texture to the colormapper.
NodeInfoContainerType m_nodeInfo
This map is needed to keep track of several node specific settings.
bool moveToBottom(osg::ref_ptr< WGETexture3D > texture)
Move the specified texture down in the list, directly to the bottom.
void resetSortIndices()
Reset all sort indices.
bool moveDown(osg::ref_ptr< WGETexture3D > texture)
Move the specified texture one item down in the list.
std::vector< osg::ref_ptr< osg::Node > > NodeList
a bunch of nodes.
boost::signals2::signal< void(osg::ref_ptr< WGETexture3D >) > m_registerSignal
Called whenever a texture got registered.
boost::signals2::connection subscribeSignal(TextureListSignal signal, TextureRegisterHandler notifier)
Subscribe to the specified signal.
bool moveUp(osg::ref_ptr< WGETexture3D > texture)
Move the specified texture one item up in the list.
This callback allows you a simple usage of callbacks in your module.
Class encapsulating the OSG Program class for a more convenient way of adding and modifying shader.
Exception thrown if a notifier could not be subscribed to a signal.
static WPVBaseTypes::PV_INT getUnsetSortIndex()
Get the index used to refer to an unset sort index.
static MatrixType identity()
Returns an identity matrix.
T::iterator Iterator
A typedef for the correct iterator to traverse this sequence container.
std::pair< Iterator, bool > insert(const value_type &x)
Inserts the specified element.
T::const_iterator ConstIterator
A typedef for the correct const iterator useful to traverse this sequence container.
std::shared_ptr< WSharedObjectTicketRead< T > > ReadTicket
Type for read tickets.
ReadTicket getReadTicket() const
Returns a ticket to get read access to the contained data.
std::shared_ptr< WSharedObjectTicketWrite< T > > WriteTicket
Type for write tickets.
WriteTicket getWriteTicket(bool suppressNotify=false) const
Returns a ticket to get write access to the contained data.
std::shared_ptr< WCondition > getChangeCondition() const
This condition fires whenever the encapsulated object changed.
size_t size() const
The size of the container.
void remove(const typename S::value_type &element)
Searches and removes the specified element.
void push_front(const typename S::value_type &x)
Adds a new element at the beginning of the container.
void replace(const typename S::value_type &oldValue, const typename S::value_type &newValue)
Replaces the specified old value by a new one.
size_t count(const value_type &value)
Counts the number of occurrences of the specified value inside the container.
S::iterator Iterator
A typedef for the correct iterator to traverse this sequence container.
S::const_iterator ConstIterator
A typedef for the correct const iterator useful to traverse this sequence container.
std::string toString(const T &value)
Convert a given value to a string.
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.
size_t getMaxTexUnits()
Returns the maximum number of textures that can be bound to a node.
void unbindTexture(osg::ref_ptr< osg::Node > node, size_t unit, size_t count=1)
Removes the binding associated with the specified unit.
WStreamedLogger debug(const std::string &source)
Logging a debug message.
Simple structure to store some additional node-related info like texture units and so on.