OpenWalnut
1.5.0dev
|
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. More... | |
typedef TextureContainerType::Iterator | TextureIterator |
Iterator to access the texture list. More... | |
typedef TextureContainerType::ConstIterator | TextureConstIterator |
Const iterator to access the texture list. More... | |
typedef boost::function< void(osg::ref_ptr< WGETexture3D >) > | TextureRegisterHandler |
The type of handler used for being notified about added textures. More... | |
typedef TextureRegisterHandler | TextureDeregisterHandler |
The type of handler used for being notified about removed textures. More... | |
typedef boost::function< void(osg::ref_ptr< WGETexture3D >, osg::ref_ptr< WGETexture3D >) > | TextureReplaceHandler |
The type of handler used for being notified about replaced textures. More... | |
typedef boost::function< void(void) > | TextureSortHandler |
The type of handler called whenever the texture list got resorted. More... | |
typedef std::vector< osg::ref_ptr< osg::Node > > | NodeList |
a bunch of nodes. More... | |
Public Member Functions | |
virtual | ~WGEColormapping () |
Destructor. More... | |
template<typename Comparator > | |
void | sort (Comparator comp) |
Resorts the texture list using the specified comparator. More... | |
template<typename Comparator > | |
void | stableSort (Comparator comp) |
Resorts the texture list using the specified comparator using a stable sorting algorithm. More... | |
void | sortByIndex () |
Sort the texture list by the indices that have been stored in each texture's sortIndex. More... | |
void | setSortIndices () |
This function sets the index of a texture in the list to this texture's WGETexture::sortIndex(). More... | |
void | resetSortIndices () |
Reset all sort indices. More... | |
bool | moveToTop (osg::ref_ptr< WGETexture3D > texture) |
Move the specified texture up in the list, directly to the top. More... | |
bool | moveToBottom (osg::ref_ptr< WGETexture3D > texture) |
Move the specified texture down in the list, directly to the bottom. More... | |
bool | moveUp (osg::ref_ptr< WGETexture3D > texture) |
Move the specified texture one item up in the list. More... | |
bool | moveDown (osg::ref_ptr< WGETexture3D > texture) |
Move the specified texture one item down in the list. More... | |
bool | moveTo (osg::ref_ptr< WGETexture3D > texture, size_t idx) |
Move the texture to the specified index. More... | |
size_t | size () const |
Counts the number of textures in the colormapper. More... | |
boost::signals2::connection | subscribeSignal (TextureListSignal signal, TextureRegisterHandler notifier) |
Subscribe to the specified signal. More... | |
boost::signals2::connection | subscribeSignal (TextureListSignal signal, TextureReplaceHandler notifier) |
Subscribe to the specified signal. More... | |
boost::signals2::connection | subscribeSignal (TextureListSignal signal, TextureSortHandler notifier) |
Subscribe to the specified signal. More... | |
TextureContainerType::ReadTicket | getReadTicket () |
Returns a read ticket to the texture array. More... | |
WBoundingBox | getBoundingBox () const |
This returns the bounding box of all the data textures. More... | |
WCondition::SPtr | getChangeCondition () const |
Returns the condition firing if the texture list changes (sort, replace, add or remove). More... | |
Static Public Member Functions | |
static std::shared_ptr< WGEColormapping > | instance () |
Returns instance of the module factory to use to create modules. More... | |
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. More... | |
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. More... | |
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. More... | |
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. More... | |
static void | registerTexture (osg::ref_ptr< WGETexture3D > texture, std::string name="") |
Register the specified texture to the colormapper. More... | |
static void | deregisterTexture (osg::ref_ptr< WGETexture3D > texture) |
De-register the specified texture to the colormapper. More... | |
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. More... | |
Protected Member Functions | |
WGEColormapping () | |
Default constructor. More... | |
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. More... | |
void | registerTextureInst (osg::ref_ptr< WGETexture3D > texture, std::string name) |
Register the specified texture to the colormapper. More... | |
void | deregisterTextureInst (osg::ref_ptr< WGETexture3D > texture) |
De-register the specified texture to the colormapper. More... | |
void | replaceTextureInst (osg::ref_ptr< WGETexture3D > old, osg::ref_ptr< WGETexture3D > newTex, std::string name="") |
Replaces the specified texture with the given new one. More... | |
void | callback (osg::Node *node) |
This callback handles all the updates needed. More... | |
void | textureUpdate () |
Called whenever the texture list is updated. More... | |
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. More... | |
Private Member Functions | |
void | updateBounds () |
Updates the bounding box information. More... | |
Private Attributes | |
TextureContainerType | m_textures |
The textures managed by this instance. More... | |
NodeInfoContainerType | m_nodeInfo |
This map is needed to keep track of several node specific settings. More... | |
boost::signals2::signal< void(osg::ref_ptr< WGETexture3D >) > | m_registerSignal |
Called whenever a texture got registered. More... | |
boost::signals2::signal< void(osg::ref_ptr< WGETexture3D >) > | m_deregisterSignal |
Called whenever a texture got removed. More... | |
boost::signals2::signal< void(osg::ref_ptr< WGETexture3D >, osg::ref_ptr< WGETexture3D >) > | m_replaceSignal |
Called whenever a texture got replaced. More... | |
boost::signals2::signal< void(void) > | m_sortSignal |
Called whenever the texture list got resorted. More... | |
WSharedObject< WBoundingBox > | m_boundingBox |
The bounding box of all the textures. More... | |
Static Private Attributes | |
static std::shared_ptr< WGEColormapping > | m_instance = std::shared_ptr< WGEColormapping >() |
Singleton instance of WGEColormapping. More... | |
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 52 of file WGEColormapping.h.
|
private |
The alias for a shared container with a set of node-nodeInfo pairs.
Definition at line 411 of file WGEColormapping.h.
typedef std::vector< osg::ref_ptr< osg::Node > > WGEColormapping::NodeList |
a bunch of nodes.
Definition at line 105 of file WGEColormapping.h.
Const iterator to access the texture list.
Definition at line 68 of file WGEColormapping.h.
typedef WSharedSequenceContainer< std::vector< osg::ref_ptr< WGETexture3D > > > WGEColormapping::TextureContainerType |
The alias for a shared container.
Definition at line 58 of file WGEColormapping.h.
The type of handler used for being notified about removed textures.
Definition at line 78 of file WGEColormapping.h.
Iterator to access the texture list.
Definition at line 63 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 73 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 83 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 88 of file WGEColormapping.h.
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 268 of file WGEColormapping.h.
|
virtual |
Destructor.
Definition at line 94 of file WGEColormapping.cpp.
|
protected |
Default constructor.
Definition at line 87 of file WGEColormapping.cpp.
References WSharedObject< T >::getChangeCondition(), m_boundingBox, m_textures, and textureUpdate().
Referenced by instance().
|
static |
Apply the colormapping to a list of nodes which all use the same shader.
nodes | the node list. |
shader | the 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. |
startTexUnit | the first texture unit allowed to be used |
Definition at line 125 of file WGEColormapping.cpp.
References WMatrixFixed< double, 4, 4 >::identity(), and instance().
|
static |
Apply the colormapping to a list of nodes using the same shader.
nodes | the node-list. |
shader | the 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. |
preTransform | Transformation 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. |
startTexUnit | the first texture unit allowed to be used |
Definition at line 120 of file WGEColormapping.cpp.
References instance().
|
static |
Apply the colormapping to the specified node.
node | the node. |
shader | the 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. |
startTexUnit | the first texture unit allowed to be used |
Definition at line 109 of file WGEColormapping.cpp.
References WMatrixFixed< double, 4, 4 >::identity(), and instance().
|
static |
Apply the colormapping to the specified node.
node | the node. |
shader | the 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. |
preTransform | Transformation 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. |
startTexUnit | the first texture unit allowed to be used |
Definition at line 114 of file WGEColormapping.cpp.
References instance().
Referenced by WMArbitraryPlane::initPlane(), WMFiberDisplay::moduleMain(), WMImageSpaceLIC::moduleMain(), WMImageSpaceTensorLIC::moduleMain(), WMIsosurfaceRaytracer::moduleMain(), WMNavigationSlices::moduleMain(), WMProjectionsAsContext::moduleMain(), WMTemplateColormapping::moduleMain(), WMVoxelizer::moduleMain(), WMIsosurface::renderMesh(), WMSplineSurface::renderMesh(), WMSurfaceIllustrator::renderMesh(), and WMTriangleMeshRenderer::renderMesh().
|
protected |
Apply the colormapping to the specified nodes.
nodes | the nodes. |
preTransform | Transformation 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. |
shader | the 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. |
startTexUnit | the first texture unit allowed to be used |
Definition at line 145 of file WGEColormapping.cpp.
References callback(), WSharedAssociativeContainer< T >::insert(), and m_nodeInfo.
|
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.
node |
Definition at line 295 of file WGEColormapping.cpp.
References wge::bindTexture(), wge::getMaxTexUnits(), WSharedObject< T >::getReadTicket(), m_nodeInfo, m_textures, string_utils::toString(), and wge::unbindTexture().
Referenced by applyInst().
|
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.
texture | the texture to remove |
Definition at line 135 of file WGEColormapping.cpp.
References instance().
Referenced by WMColormapper::moduleMain(), WMFunctionalMRIViewer::moduleMain(), WMImageExtractor::moduleMain(), WMPaintTexture::moduleMain(), and WMData::updateColorMap().
|
protected |
De-register the specified texture to the colormapper.
The texture is the automatically removed from all users of WGEColormapping.
texture | the texture to remove |
Definition at line 190 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.
Definition at line 242 of file WGEColormapping.cpp.
References 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.
Definition at line 532 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.
Definition at line 527 of file WGEColormapping.cpp.
References WSharedObject< T >::getReadTicket(), and m_textures.
|
static |
Returns instance of the module factory to use to create modules.
Definition at line 99 of file WGEColormapping.cpp.
References m_instance, and WGEColormapping().
Referenced by WModuleProjectFileCombiner::apply(), apply(), deregisterTexture(), WMNavigationSlices::initOSG(), WMNavigationSlices::moduleMain(), WQtColormapper::moveItemBottom(), WQtColormapper::moveItemDown(), WQtColormapper::moveItemTop(), WQtColormapper::moveItemUp(), registerTexture(), replaceTexture(), WQtColormapper::rowsMoved(), WModuleProjectFileCombiner::save(), WQtColormapper::update(), and WQtColormapper::WQtColormapper().
bool WGEColormapping::moveDown | ( | osg::ref_ptr< WGETexture3D > | texture | ) |
Move the specified texture one item down in the list.
Causes the sort signal to fire.
texture | the texture swapped with its descendant |
Definition at line 332 of file WGEColormapping.cpp.
References WSharedObject< T >::getWriteTicket(), m_sortSignal, and m_textures.
bool WGEColormapping::moveTo | ( | osg::ref_ptr< WGETexture3D > | texture, |
size_t | idx | ||
) |
Move the texture to the specified index.
If the texture is not in the list, nothing happens.
texture | the texture to move |
idx | the target index |
Definition at line 442 of file WGEColormapping.cpp.
References WSharedObject< T >::getWriteTicket(), m_sortSignal, and m_textures.
bool WGEColormapping::moveToBottom | ( | osg::ref_ptr< WGETexture3D > | texture | ) |
Move the specified texture down in the list, directly to the bottom.
Causes the sort signal to fire.
texture | the texture swapped with its descendant |
Definition at line 414 of file WGEColormapping.cpp.
References WSharedObject< T >::getWriteTicket(), m_sortSignal, and m_textures.
bool WGEColormapping::moveToTop | ( | osg::ref_ptr< WGETexture3D > | texture | ) |
Move the specified texture up in the list, directly to the top.
Causes the sort signal to fire.
texture | the texture swapped with its ascendant |
Definition at line 386 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.
texture | the texture swapped with its ascendant |
Definition at line 359 of file WGEColormapping.cpp.
References WSharedObject< T >::getWriteTicket(), m_sortSignal, and m_textures.
|
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.
texture | the texture to add |
name | the name of the texture to add |
Definition at line 130 of file WGEColormapping.cpp.
References instance().
Referenced by WMPaintTexture::createTexture(), WMColormapper::moduleMain(), WMFunctionalMRIViewer::moduleMain(), WMImageExtractor::moduleMain(), and WMData::updateColorMap().
|
protected |
Register the specified texture to the colormapper.
The registered texture is the automatically applied to all users of WGEColormapping.
texture | the texture to add |
name | the name of the texture. |
Definition at line 175 of file WGEColormapping.cpp.
References WSharedSequenceContainer< S >::count(), wlog::debug(), m_registerSignal, m_textures, WSharedSequenceContainer< S >::push_front(), and updateBounds().
Referenced by replaceTextureInst().
|
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.
old | the texture to remove |
newTex | the new texture to put at the position of the old one |
name | the name of the texture. |
Definition at line 140 of file WGEColormapping.cpp.
References instance().
Referenced by WMColormapper::moduleMain(), and WMImageExtractor::moduleMain().
|
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.
old | the texture to remove |
newTex | the new texture to put at the position of the old one |
name | the name of the texture. |
Definition at line 201 of file WGEColormapping.cpp.
References WSharedSequenceContainer< S >::count(), wlog::debug(), m_replaceSignal, m_textures, registerTextureInst(), WSharedSequenceContainer< S >::replace(), and updateBounds().
void WGEColormapping::resetSortIndices | ( | ) |
Reset all sort indices.
This can be useful when loading new project files with new sort indices.
Definition at line 286 of file WGEColormapping.cpp.
References WSharedObject< T >::getReadTicket(), WGETexture< TextureType >::getUnsetSortIndex(), and m_textures.
void WGEColormapping::setSortIndices | ( | ) |
This function sets the index of a texture in the list to this texture's WGETexture::sortIndex().
This can be used later using sortByIndex().
Definition at line 275 of file WGEColormapping.cpp.
References WSharedObject< T >::getReadTicket(), and m_textures.
size_t WGEColormapping::size | ( | ) | const |
Counts the number of textures in the colormapper.
Definition at line 487 of file WGEColormapping.cpp.
References m_textures, and WSharedSequenceContainer< S >::size().
void WGEColormapping::sort | ( | Comparator | comp | ) |
Resorts the texture list using the specified comparator.
Comparator | the comparator type. Usually a boost::function or class providing the operator(). |
comp | the comparator |
Definition at line 450 of file WGEColormapping.h.
References m_textures, and WSharedSequenceContainer< S >::sort().
void WGEColormapping::sortByIndex | ( | ) |
Sort the texture list by the indices that have been stored in each texture's sortIndex.
Definition at line 269 of file WGEColormapping.cpp.
References stableSort().
void WGEColormapping::stableSort | ( | Comparator | comp | ) |
Resorts the texture list using the specified comparator using a stable sorting algorithm.
Comparator | the comparator type. Usually a boost::function or class providing the operator(). |
comp | the comparator |
Definition at line 456 of file WGEColormapping.h.
References m_textures, and WSharedSequenceContainer< S >::stableSort().
Referenced by sortByIndex().
boost::signals2::connection WGEColormapping::subscribeSignal | ( | TextureListSignal | signal, |
TextureRegisterHandler | notifier | ||
) |
Subscribe to the specified signal.
See TextureListSignal for details about their meaning.
signal | the signal to subscribe |
notifier | the notifier |
Definition at line 492 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.
signal | the signal to subscribe |
notifier | the notifier |
Definition at line 505 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.
signal | the signal to subscribe |
notifier | the notifier |
Definition at line 516 of file WGEColormapping.cpp.
References m_sortSignal, and Sorted.
|
protected |
Called whenever the texture list is updated.
Definition at line 247 of file WGEColormapping.cpp.
References WSharedObject< T >::getWriteTicket(), and m_nodeInfo.
Referenced by WGEColormapping().
|
private |
Updates the bounding box information.
This is called for every write-update in m_textures.
Definition at line 222 of file WGEColormapping.cpp.
References WSharedObject< T >::getReadTicket(), m_boundingBox, and m_textures.
Referenced by deregisterTextureInst(), registerTextureInst(), and replaceTextureInst().
|
private |
The bounding box of all the textures.
Definition at line 441 of file WGEColormapping.h.
Referenced by getBoundingBox(), updateBounds(), and WGEColormapping().
|
private |
Called whenever a texture got removed.
Definition at line 426 of file WGEColormapping.h.
Referenced by deregisterTextureInst(), and subscribeSignal().
|
staticprivate |
Singleton instance of WGEColormapping.
Definition at line 391 of file WGEColormapping.h.
Referenced by instance().
|
private |
This map is needed to keep track of several node specific settings.
Definition at line 416 of file WGEColormapping.h.
Referenced by applyInst(), callback(), and textureUpdate().
|
private |
Called whenever a texture got registered.
Definition at line 421 of file WGEColormapping.h.
Referenced by registerTextureInst(), and subscribeSignal().
|
private |
Called whenever a texture got replaced.
Definition at line 431 of file WGEColormapping.h.
Referenced by replaceTextureInst(), and subscribeSignal().
|
private |
Called whenever the texture list got resorted.
Definition at line 436 of file WGEColormapping.h.
Referenced by moveDown(), moveTo(), moveToBottom(), moveToTop(), moveUp(), and subscribeSignal().
|
private |
The textures managed by this instance.
Definition at line 396 of file WGEColormapping.h.
Referenced by callback(), deregisterTextureInst(), getChangeCondition(), getReadTicket(), moveDown(), moveTo(), moveToBottom(), moveToTop(), moveUp(), registerTextureInst(), replaceTextureInst(), resetSortIndices(), setSortIndices(), size(), sort(), stableSort(), updateBounds(), and WGEColormapping().