Commit 2e70a768 authored by schurade's avatar schurade
Browse files

[ADD] function for creating a 3d texture in the GE

parent 1c8b0446
......@@ -88,3 +88,27 @@ boost::shared_ptr<WGEViewer> WGraphicsEngine::createViewer( osg::ref_ptr<WindowD
return viewer;
}
osg::Texture3D* WGraphicsEngine::createTexture3D( int8_t* source, int components )
{
if ( components == 1)
{
osg::ref_ptr< osg::Image > ima = new osg::Image;
ima->allocateImage( 160, 200, 160, GL_LUMINANCE, GL_UNSIGNED_BYTE );
unsigned char* data = ima->data();
for ( unsigned int i = 0; i < 160* 200* 160 ; ++i )
{
data[i] = source[i];
}
osg::Texture3D* texture3D = new osg::Texture3D;
texture3D->setFilter( osg::Texture3D::MIN_FILTER, osg::Texture3D::LINEAR );
texture3D->setFilter( osg::Texture3D::MAG_FILTER, osg::Texture3D::LINEAR );
texture3D->setWrap( osg::Texture3D::WRAP_R, osg::Texture3D::REPEAT );
texture3D->setImage( ima );
texture3D->setResizeNonPowerOfTwoHint( false );
return texture3D;
}
return 0;
}
......@@ -35,6 +35,7 @@
#include <osg/Camera>
#include <osgViewer/Viewer>
#include <osg/Texture3D>
#include "WGEScene.h"
#include "WGEGraphicsWindow.h"
......@@ -70,14 +71,14 @@ public:
/**
* Return the path where the shaders are expected to be located.
*
*
* \return shader path
*/
std::string getShaderPath();
/**
/**
* Creates a new viewer. Does basic initialization and sets the default scene.
*
*
* \param wdata the WindowData instance for the widget to use as render widget
* \param x X coordinate of widget where to create the context.
* \param y Y coordinate of widget where to create the context.
......@@ -88,6 +89,19 @@ public:
*/
boost::shared_ptr<WGEViewer> createViewer( osg::ref_ptr<WindowData> wdata, int x, int y, int width, int height );
/**
* Creates a 3d texture from a dataset. This function will be overloaded for the
* various data types. A template function is not recommended due to the different commands
* in the image creation.
*
* TODO(schurade): create other functions once dataset meta data is available again
*
* \param source Pointer to the raw data of a dataset
* \param components Number of values used in a Voxel, usually 1, 3 or 4
* \return Pointer to a new texture3D
*/
osg::Texture3D* createTexture3D( int8_t* source, int components = 1 );
protected:
/**
......@@ -100,12 +114,12 @@ protected:
*/
virtual void threadMain();
/**
/**
* All registered viewer.
*/
std::list<boost::shared_ptr<WGEViewer> > m_Viewer;
/**
/**
* Mutex used to lock the list of viewers.
*/
boost::mutex m_ViewerLock;
......
......@@ -134,21 +134,7 @@ void WNavigationSliceModule::threadMain()
int8_t > >( ds->getValueSet() );
int8_t* source = const_cast< int8_t* > ( vs->rawData() );
osg::ref_ptr< osg::Image > ima = new osg::Image;
ima->allocateImage( 160, 200, 160, GL_LUMINANCE, GL_UNSIGNED_BYTE );
unsigned char* data = ima->data();
for ( unsigned int i = 0; i < 160* 200* 160 ; ++i )
{
data[i] = source[i];
}
osg::Texture3D* texture3D = new osg::Texture3D;
texture3D->setFilter( osg::Texture3D::MIN_FILTER, osg::Texture3D::LINEAR );
texture3D->setFilter( osg::Texture3D::MAG_FILTER, osg::Texture3D::LINEAR );
texture3D->setWrap( osg::Texture3D::WRAP_R, osg::Texture3D::REPEAT );
texture3D->setImage( ima );
texture3D->setResizeNonPowerOfTwoHint( false );
osg::Texture3D* texture3D = WKernel::getRunningKernel()->getGraphicsEngine()->createTexture3D( source );
osg::StateSet* sliceState = m_sliceNode->getOrCreateStateSet();
......
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