OpenWalnut  1.3.1
Classes | Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Private Types | Private Member Functions | Private Attributes | Static Private Attributes | List of all members
WGEColormapping Class Reference

Class implements a manager for multiple 3D textures. More...

#include <WGEColormapping.h>

Classes

struct  NodeInfo
 Simple structure to store some additional node-related info like texture units and so on. More...

Public Types

enum  TextureListSignal { Registered = 0, Deregistered, Replaced, Sorted }
 Possible signals that can be subscribed for being notified about texture list changes. More...
typedef
WSharedSequenceContainer
< std::vector< osg::ref_ptr
< WGETexture3D > > > 
TextureContainerType
 The alias for a shared container.
typedef
TextureContainerType::Iterator 
TextureIterator
 Iterator to access the texture list.
typedef
TextureContainerType::ConstIterator 
TextureConstIterator
 Const iterator to access the texture list.
typedef boost::function< void(osg::ref_ptr
< WGETexture3D >) > 
TextureRegisterHandler
 The type of handler used for being notified about added textures.
typedef TextureRegisterHandler TextureDeregisterHandler
 The type of handler used for being notified about removed textures.
typedef boost::function< void(osg::ref_ptr
< WGETexture3D >, osg::ref_ptr
< WGETexture3D >) > 
TextureReplaceHandler
 The type of handler used for being notified about replaced textures.
typedef boost::function< void(void) > TextureSortHandler
 The type of handler called whenever the texture list got resorted.
typedef std::vector
< osg::ref_ptr< osg::Node > > 
NodeList
 a bunch of nodes.

Public Member Functions

virtual ~WGEColormapping ()
 Destructor.
template<typename Comparator >
void sort (Comparator comp)
 Resorts the texture list using the specified comparator.
bool moveUp (osg::ref_ptr< WGETexture3D > texture)
 Move the specified texture one item up in the list.
bool moveDown (osg::ref_ptr< WGETexture3D > texture)
 Move the specified texture one item down in the list.
size_t size () const
 Counts the number of textures in the colormapper.
boost::signals2::connection subscribeSignal (TextureListSignal signal, TextureRegisterHandler notifier)
 Subscribe to the specified signal.
boost::signals2::connection subscribeSignal (TextureListSignal signal, TextureReplaceHandler notifier)
 Subscribe to the specified signal.
boost::signals2::connection subscribeSignal (TextureListSignal signal, TextureSortHandler notifier)
 Subscribe to the specified signal.
TextureContainerType::ReadTicket getReadTicket ()
 Returns a read ticket to the texture array.
WBoundingBox getBoundingBox () const
 This returns the bounding box of all the data textures.
WCondition::SPtr getChangeCondition () const
 Returns the condition firing if the texture list changes (sort, replace, add or remove).

Static Public Member Functions

static boost::shared_ptr
< WGEColormapping
instance ()
 Returns instance of the module factory to use to create modules.
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.
static void apply (NodeList nodes, WMatrix4d preTransform=WMatrix4d::identity(), osg::ref_ptr< WGEShader > shader=osg::ref_ptr< WGEShader >(), size_t startTexUnit=0)
 Apply the colormapping to a list of nodes using the same shader.
static void apply (osg::ref_ptr< osg::Node > node, osg::ref_ptr< WGEShader > shader=osg::ref_ptr< WGEShader >(), size_t startTexUnit=0)
 Apply the colormapping to the specified node.
static void apply (NodeList nodes, osg::ref_ptr< WGEShader > shader=osg::ref_ptr< WGEShader >(), size_t startTexUnit=0)
 Apply the colormapping to a list of nodes which all use the same shader.
static void registerTexture (osg::ref_ptr< WGETexture3D > texture, std::string name="")
 Register the specified texture to the colormapper.
static void deregisterTexture (osg::ref_ptr< WGETexture3D > texture)
 De-register the specified texture to the colormapper.
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.

Protected Member Functions

 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.
void registerTextureInst (osg::ref_ptr< WGETexture3D > texture, std::string name)
 Register the specified texture to the colormapper.
void deregisterTextureInst (osg::ref_ptr< WGETexture3D > texture)
 De-register the specified texture to the colormapper.
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 callback (osg::Node *node)
 This callback handles all the updates needed.
void textureUpdate ()
 Called whenever the texture list is updated.

Private Types

typedef
WSharedAssociativeContainer
< std::map< osg::Node
*, NodeInfo *, std::less
< osg::Node * > > > 
NodeInfoContainerType
 The alias for a shared container with a set of node-nodeInfo pairs.

Private Member Functions

void updateBounds ()
 Updates the bounding box information.

Private Attributes

TextureContainerType m_textures
 The textures managed by this instance.
NodeInfoContainerType m_nodeInfo
 This map is needed to keep track of several node specific settings.
boost::signals2::signal< void(osg::ref_ptr
< WGETexture3D >) > 
m_registerSignal
 Called whenever a texture got registered.
boost::signals2::signal< void(osg::ref_ptr
< WGETexture3D >) > 
m_deregisterSignal
 Called whenever a texture got removed.
boost::signals2::signal< void(osg::ref_ptr
< WGETexture3D >, osg::ref_ptr
< WGETexture3D >) > 
m_replaceSignal
 Called whenever a texture got replaced.
boost::signals2::signal< void(void) > m_sortSignal
 Called whenever the texture list got resorted.
WSharedObject< WBoundingBoxm_boundingBox
 The bounding box of all the textures.

Static Private Attributes

static boost::shared_ptr
< WGEColormapping
m_instance = boost::shared_ptr< WGEColormapping >()
 Singleton instance of WGEColormapping.

Detailed Description

Class implements a manager for multiple 3D textures.

They can be applied to arbitrary osg::Node. This allows very comfortable use of dataset based colormapping. The only requirement is that your geometry/node needs to specify texture coordinates in Object Space. That means: the texture coordinates equal the regular 3D grid of the texture.

Definition at line 55 of file WGEColormapping.h.

Member Typedef Documentation

typedef WSharedAssociativeContainer< std::map< osg::Node*, NodeInfo*, std::less< osg::Node* > > > WGEColormapping::NodeInfoContainerType
private

The alias for a shared container with a set of node-nodeInfo pairs.

Definition at line 362 of file WGEColormapping.h.

typedef std::vector< osg::ref_ptr< osg::Node > > WGEColormapping::NodeList

a bunch of nodes.

Definition at line 108 of file WGEColormapping.h.

Const iterator to access the texture list.

Definition at line 71 of file WGEColormapping.h.

The alias for a shared container.

Definition at line 61 of file WGEColormapping.h.

The type of handler used for being notified about removed textures.

Definition at line 81 of file WGEColormapping.h.

Iterator to access the texture list.

Definition at line 66 of file WGEColormapping.h.

typedef boost::function< void ( osg::ref_ptr< WGETexture3D > ) > WGEColormapping::TextureRegisterHandler

The type of handler used for being notified about added textures.

Definition at line 76 of file WGEColormapping.h.

typedef boost::function< void ( osg::ref_ptr< WGETexture3D >, osg::ref_ptr< WGETexture3D > ) > WGEColormapping::TextureReplaceHandler

The type of handler used for being notified about replaced textures.

Definition at line 86 of file WGEColormapping.h.

typedef boost::function< void ( void ) > WGEColormapping::TextureSortHandler

The type of handler called whenever the texture list got resorted.

Definition at line 91 of file WGEColormapping.h.

Member Enumeration Documentation

Possible signals that can be subscribed for being notified about texture list changes.

Enumerator:
Registered 

texture got added

Deregistered 

texture got removed

Replaced 

texture got replaced

Sorted 

texture list was resorted

Definition at line 219 of file WGEColormapping.h.

Constructor & Destructor Documentation

WGEColormapping::~WGEColormapping ( )
virtual

Destructor.

Definition at line 95 of file WGEColormapping.cpp.

WGEColormapping::WGEColormapping ( )
protected

Member Function Documentation

void WGEColormapping::apply ( osg::ref_ptr< osg::Node >  node,
WMatrix4d  preTransform = WMatrix4d::identity(),
osg::ref_ptr< WGEShader shader = osg::ref_ptr< WGEShader >(),
size_t  startTexUnit = 0 
)
static

Apply the colormapping to the specified node.

Parameters
nodethe node.
shaderthe shader to use for colormapping. Provide your own shader here to let WGEColormap set some defines needed. If not specified, a default shader is used.
preTransformTransformation matrix getting applied to your texture coordinates before applying texture matrices. This allows you to specify any kind of texture coordinates as long as you use this matrix to transform them to the right space.
startTexUnitthe first texture unit allowed to be used

Definition at line 115 of file WGEColormapping.cpp.

References instance().

void WGEColormapping::apply ( NodeList  nodes,
WMatrix4d  preTransform = WMatrix4d::identity(),
osg::ref_ptr< WGEShader shader = osg::ref_ptr< WGEShader >(),
size_t  startTexUnit = 0 
)
static

Apply the colormapping to a list of nodes using the same shader.

Parameters
nodesthe node-list.
shaderthe shader to use for colormapping. Provide your own shader here to let WGEColormap set some defines needed. If not specified, a default shader is used.
preTransformTransformation matrix getting applied to your texture coordinates before applying texture matrices. This allows you to specify any kind of texture coordinates as long as you use this matrix to transform them to the right space.
startTexUnitthe first texture unit allowed to be used

Definition at line 121 of file WGEColormapping.cpp.

References instance().

void WGEColormapping::apply ( osg::ref_ptr< osg::Node >  node,
osg::ref_ptr< WGEShader shader = osg::ref_ptr< WGEShader >(),
size_t  startTexUnit = 0 
)
static

Apply the colormapping to the specified node.

Parameters
nodethe node.
shaderthe shader to use for colormapping. Provide your own shader here to let WGEColormap set some defines needed. If not specified, a default shader is used.
startTexUnitthe first texture unit allowed to be used

Definition at line 110 of file WGEColormapping.cpp.

References WMatrixFixed< double, 4, 4 >::identity(), and instance().

void WGEColormapping::apply ( NodeList  nodes,
osg::ref_ptr< WGEShader shader = osg::ref_ptr< WGEShader >(),
size_t  startTexUnit = 0 
)
static

Apply the colormapping to a list of nodes which all use the same shader.

Parameters
nodesthe node list.
shaderthe shader to use for colormapping. Provide your own shader here to let WGEColormap set some defines needed. If not specified, a default shader is used.
startTexUnitthe first texture unit allowed to be used

Definition at line 126 of file WGEColormapping.cpp.

References WMatrixFixed< double, 4, 4 >::identity(), and instance().

void WGEColormapping::applyInst ( NodeList  nodes,
WMatrix4d  preTransform = WMatrix4d::identity(),
osg::ref_ptr< WGEShader shader = osg::ref_ptr< WGEShader >(),
size_t  startTexUnit = 0 
)
protected

Apply the colormapping to the specified nodes.

Parameters
nodesthe nodes.
preTransformTransformation matrix getting applied to your texture coordinates before applying texture matrices. This allows you to specify any kind of texture coordinates as long as you use this matrix to transform them to the right space.
shaderthe shader to use for colormapping. Provide your own shader here to let WGEColormap set some defines needed. If not specified, a default shader is used.
startTexUnitthe first texture unit allowed to be used

Definition at line 146 of file WGEColormapping.cpp.

References callback(), WSharedAssociativeContainer< T >::insert(), m_nodeInfo, WGEColormapping::NodeInfo::m_preTransform, WGEColormapping::NodeInfo::m_rebind, and WGEColormapping::NodeInfo::m_texUnitStart.

void WGEColormapping::callback ( osg::Node *  node)
protected

This callback handles all the updates needed.

It is called by the callback instance every update cycle for each node using this WGEColormapping instance.

Parameters
node

Definition at line 257 of file WGEColormapping.cpp.

References wge::bindTexture(), wge::getMaxTexUnits(), WSharedObject< T >::getReadTicket(), m_nodeInfo, WGEColormapping::NodeInfo::m_rebind, m_textures, WGEColormapping::NodeInfo::m_texUnitStart, string_utils::toString(), and wge::unbindTexture().

Referenced by applyInst().

void WGEColormapping::deregisterTexture ( osg::ref_ptr< WGETexture3D texture)
static

De-register the specified texture to the colormapper.

The texture is the automatically removed from all users of WGEColormapping. If the texture is not in the list, nothing happens.

Parameters
texturethe texture to remove

Definition at line 136 of file WGEColormapping.cpp.

References instance().

void WGEColormapping::deregisterTextureInst ( osg::ref_ptr< WGETexture3D texture)
protected

De-register the specified texture to the colormapper.

The texture is the automatically removed from all users of WGEColormapping.

Parameters
texturethe texture to remove

Definition at line 191 of file WGEColormapping.cpp.

References WSharedSequenceContainer< S >::count(), wlog::debug(), m_deregisterSignal, m_textures, WSharedSequenceContainer< S >::remove(), and updateBounds().

WBoundingBox WGEColormapping::getBoundingBox ( ) const

This returns the bounding box of all the data textures.

This is very useful if you implement an universal color-mapped exploration tool. It returns a copy of the current bounding box. Please note that this can change any moment.

Returns
the bounding box.

Definition at line 243 of file WGEColormapping.cpp.

References WSharedObject< T >::getReadTicket(), and m_boundingBox.

WCondition::SPtr WGEColormapping::getChangeCondition ( ) const

Returns the condition firing if the texture list changes (sort, replace, add or remove).

If you are interested in a certain event only, use subscribeSignal.

Returns
the change condition

Definition at line 393 of file WGEColormapping.cpp.

References WSharedObject< T >::getChangeCondition(), and m_textures.

WGEColormapping::TextureContainerType::ReadTicket WGEColormapping::getReadTicket ( )

Returns a read ticket to the texture array.

Useful to iterate the textures.

Returns
the read ticket

Definition at line 388 of file WGEColormapping.cpp.

References WSharedObject< T >::getReadTicket(), and m_textures.

boost::shared_ptr< WGEColormapping > WGEColormapping::instance ( )
static

Returns instance of the module factory to use to create modules.

Returns
the running module factory.

Definition at line 100 of file WGEColormapping.cpp.

References m_instance, and WGEColormapping().

Referenced by apply(), deregisterTexture(), registerTexture(), and replaceTexture().

bool WGEColormapping::moveDown ( osg::ref_ptr< WGETexture3D texture)

Move the specified texture one item down in the list.

Causes the sort signal to fire.

Parameters
texturethe texture swapped with its descendant
Returns
true if swap was successful. False if not (texture not found, texture already at end).

Definition at line 294 of file WGEColormapping.cpp.

References WSharedObject< T >::getWriteTicket(), m_sortSignal, and m_textures.

bool WGEColormapping::moveUp ( osg::ref_ptr< WGETexture3D texture)

Move the specified texture one item up in the list.

Causes the sort signal to fire.

Parameters
texturethe texture swapped with its ascendant
Returns
true if swap was successful. False if not (texture not found, texture already at beginning).

Definition at line 321 of file WGEColormapping.cpp.

References WSharedObject< T >::getWriteTicket(), m_sortSignal, and m_textures.

void WGEColormapping::registerTexture ( osg::ref_ptr< WGETexture3D texture,
std::string  name = "" 
)
static

Register the specified texture to the colormapper.

The registered texture is the automatically applied to all users of WGEColormapping. The texture gets inserted at the beginning of the texture list.

Parameters
texturethe texture to add
namethe name of the texture to add

Definition at line 131 of file WGEColormapping.cpp.

References instance().

void WGEColormapping::registerTextureInst ( osg::ref_ptr< WGETexture3D texture,
std::string  name 
)
protected

Register the specified texture to the colormapper.

The registered texture is the automatically applied to all users of WGEColormapping.

Parameters
texturethe texture to add
namethe name of the texture.

Definition at line 176 of file WGEColormapping.cpp.

References WSharedSequenceContainer< S >::count(), wlog::debug(), m_registerSignal, m_textures, WSharedSequenceContainer< S >::push_front(), and updateBounds().

Referenced by replaceTextureInst().

void WGEColormapping::replaceTexture ( osg::ref_ptr< WGETexture3D old,
osg::ref_ptr< WGETexture3D newTex,
std::string  name = "" 
)
static

Replaces the specified texture with the given new one.

If the old texture does not exist, the new one gets inserted at the front of the list as registerTexture does.

Parameters
oldthe texture to remove
newTexthe new texture to put at the position of the old one
namethe name of the texture.

Definition at line 141 of file WGEColormapping.cpp.

References instance().

void WGEColormapping::replaceTextureInst ( osg::ref_ptr< WGETexture3D old,
osg::ref_ptr< WGETexture3D newTex,
std::string  name = "" 
)
protected

Replaces the specified texture with the given new one.

If the old texture does not exist, the new one gets inserted at the front of the list as registerTexture does.

Parameters
oldthe texture to remove
newTexthe new texture to put at the position of the old one
namethe name of the texture.

Definition at line 202 of file WGEColormapping.cpp.

References WSharedSequenceContainer< S >::count(), wlog::debug(), m_replaceSignal, m_textures, registerTextureInst(), WSharedSequenceContainer< S >::replace(), and updateBounds().

size_t WGEColormapping::size ( ) const

Counts the number of textures in the colormapper.

Returns
the number of textures.

Definition at line 348 of file WGEColormapping.cpp.

References m_textures, and WSharedSequenceContainer< S >::size().

template<typename Comparator >
void WGEColormapping::sort ( Comparator  comp)

Resorts the texture list using the specified comparator.

Template Parameters
Comparatorthe comparator type. Usually a boost::function or class providing the operator().
Parameters
compthe comparator

Definition at line 401 of file WGEColormapping.h.

References m_textures, and WSharedSequenceContainer< S >::sort().

boost::signals2::connection WGEColormapping::subscribeSignal ( TextureListSignal  signal,
TextureRegisterHandler  notifier 
)

Subscribe to the specified signal.

See TextureListSignal for details about their meaning.

Parameters
signalthe signal to subscribe
notifierthe notifier
Returns
the connection. Keep this and disconnect it properly!

Definition at line 353 of file WGEColormapping.cpp.

References Deregistered, m_deregisterSignal, m_registerSignal, and Registered.

boost::signals2::connection WGEColormapping::subscribeSignal ( TextureListSignal  signal,
TextureReplaceHandler  notifier 
)

Subscribe to the specified signal.

See TextureListSignal for details about their meaning.

Parameters
signalthe signal to subscribe
notifierthe notifier
Returns
the connection. Keep this and disconnect it properly!

Definition at line 366 of file WGEColormapping.cpp.

References m_replaceSignal, and Replaced.

boost::signals2::connection WGEColormapping::subscribeSignal ( TextureListSignal  signal,
TextureSortHandler  notifier 
)

Subscribe to the specified signal.

See TextureListSignal for details about their meaning.

Parameters
signalthe signal to subscribe
notifierthe notifier
Returns
the connection. Keep this and disconnect it properly!

Definition at line 377 of file WGEColormapping.cpp.

References m_sortSignal, and Sorted.

void WGEColormapping::textureUpdate ( )
protected

Called whenever the texture list is updated.

Definition at line 248 of file WGEColormapping.cpp.

References WSharedObject< T >::getWriteTicket(), and m_nodeInfo.

Referenced by WGEColormapping().

void WGEColormapping::updateBounds ( )
private

Updates the bounding box information.

This is called for every write-update in m_textures.

Definition at line 223 of file WGEColormapping.cpp.

References WSharedObject< T >::getReadTicket(), WSharedObject< T >::getWriteTicket(), m_boundingBox, and m_textures.

Referenced by deregisterTextureInst(), registerTextureInst(), and replaceTextureInst().

Member Data Documentation

WSharedObject< WBoundingBox > WGEColormapping::m_boundingBox
private

The bounding box of all the textures.

Definition at line 392 of file WGEColormapping.h.

Referenced by getBoundingBox(), updateBounds(), and WGEColormapping().

boost::signals2::signal< void( osg::ref_ptr< WGETexture3D > ) > WGEColormapping::m_deregisterSignal
private

Called whenever a texture got removed.

Definition at line 377 of file WGEColormapping.h.

Referenced by deregisterTextureInst(), and subscribeSignal().

boost::shared_ptr< WGEColormapping > WGEColormapping::m_instance = boost::shared_ptr< WGEColormapping >()
staticprivate

Singleton instance of WGEColormapping.

Definition at line 342 of file WGEColormapping.h.

Referenced by instance().

NodeInfoContainerType WGEColormapping::m_nodeInfo
private

This map is needed to keep track of several node specific settings.

Definition at line 367 of file WGEColormapping.h.

Referenced by applyInst(), callback(), and textureUpdate().

boost::signals2::signal< void( osg::ref_ptr< WGETexture3D > ) > WGEColormapping::m_registerSignal
private

Called whenever a texture got registered.

Definition at line 372 of file WGEColormapping.h.

Referenced by registerTextureInst(), and subscribeSignal().

boost::signals2::signal< void( osg::ref_ptr< WGETexture3D >, osg::ref_ptr< WGETexture3D > ) > WGEColormapping::m_replaceSignal
private

Called whenever a texture got replaced.

Definition at line 382 of file WGEColormapping.h.

Referenced by replaceTextureInst(), and subscribeSignal().

boost::signals2::signal< void( void ) > WGEColormapping::m_sortSignal
private

Called whenever the texture list got resorted.

Definition at line 387 of file WGEColormapping.h.

Referenced by moveDown(), moveUp(), and subscribeSignal().

TextureContainerType WGEColormapping::m_textures
private

The documentation for this class was generated from the following files: