Commit 5885043b authored by schurade's avatar schurade

[ADD] some preliminary texture loading

parent eec26e48
......@@ -45,7 +45,7 @@ std::string WSubject::getName() const
return m_name;
}
boost::shared_ptr< const WDataSet > WSubject::getDataSet( const unsigned int dataSetId ) const
boost::shared_ptr< WDataSet > WSubject::getDataSet( const unsigned int dataSetId ) const
{
if( dataSetId >= m_dataSets.size() )
throw WNoSuchDataSetException( "Index too large." );
......
......@@ -57,7 +57,7 @@ public:
* Get the pointer to the i'th WDataSet. The return type is const since we
* want to ensure that each DataSet cannot modified after retrival.
*/
boost::shared_ptr< const WDataSet > getDataSet( const unsigned int dataSetId ) const;
boost::shared_ptr< WDataSet > getDataSet( const unsigned int dataSetId ) const;
/**
* Returns a to the i'th WSubject. The return type is const since we
......
......@@ -29,10 +29,17 @@
#include <osg/Group>
#include <osg/Geode>
#include <osg/Geometry>
#include <osg/Texture3D>
#include "boost/smart_ptr.hpp"
#include "WNavigationSliceModule.h"
#include "../../kernel/WKernel.h"
#include "../../dataHandler/WDataSetSingle.h"
#include "../../dataHandler/WSubject.h"
#include "../../dataHandler/WValueSet.hpp"
#include "../../graphicsEngine/WShader.h"
WNavigationSliceModule::WNavigationSliceModule():
......@@ -40,6 +47,7 @@ WNavigationSliceModule::WNavigationSliceModule():
{
// initialize members
m_shader = boost::shared_ptr< WShader > ( new WShader( "slice" ) );
m_textureAssigned = false;
}
WNavigationSliceModule::~WNavigationSliceModule()
......@@ -70,6 +78,44 @@ void WNavigationSliceModule::threadMain()
// Since the modules run in a separate thread: such loops are possible
while ( !m_FinishRequested )
{
if ( WKernel::getRunningKernel()->getDataHandler()->getNumberOfSubjects() > 0 )
{
if ( WKernel::getRunningKernel()->getDataHandler()->getSubject(0)->getNumberOfDataSets() > 0 )
{
if ( !m_textureAssigned )
{
boost::shared_ptr< WDataSetSingle > ds = boost::shared_dynamic_cast< WDataSetSingle >(
WKernel::getRunningKernel()->getDataHandler()->getSubject( 0 )->getDataSet( 0 ) );
boost::shared_ptr< WValueSet< int8_t > > vs = boost::shared_dynamic_cast< WValueSet<
int8_t > >( ds->getValueSet() );
int8_t* source = const_cast< int8_t* > ( vs->rawData() );
std::cout << "hier gehts los" << std::endl;
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::StateSet* sliceState = m_sliceNode->getOrCreateStateSet();
sliceState->setTextureAttributeAndModes( 0, texture3D, osg::StateAttribute::ON );
m_textureAssigned = true;
}
}
}
// do fancy stuff
sleep( 1 );
}
......@@ -79,26 +125,26 @@ void WNavigationSliceModule::threadMain()
void WNavigationSliceModule::createSlices()
{
osg::Geode* m_sliceNode = new osg::Geode();
m_sliceNode = new osg::Geode();
osg::Geometry* sliceGeometry = new osg::Geometry();
m_sliceNode->addDrawable( sliceGeometry );
osg::Vec3Array* sliceVertices = new osg::Vec3Array;
sliceVertices->push_back( osg::Vec3( 0, 50, 0 ) );
sliceVertices->push_back( osg::Vec3( 0, 50, 100 ) );
sliceVertices->push_back( osg::Vec3( 100, 50, 100 ) );
sliceVertices->push_back( osg::Vec3( 100, 50, 0 ) );
sliceVertices->push_back( osg::Vec3( 50, 0, 0 ) );
sliceVertices->push_back( osg::Vec3( 50, 0, 100 ) );
sliceVertices->push_back( osg::Vec3( 50, 100, 100 ) );
sliceVertices->push_back( osg::Vec3( 50, 100, 0 ) );
sliceVertices->push_back( osg::Vec3( 0, 0, 50 ) );
sliceVertices->push_back( osg::Vec3( 0, 100, 50 ) );
sliceVertices->push_back( osg::Vec3( 100, 100, 50 ) );
sliceVertices->push_back( osg::Vec3( 100, 0, 50 ) );
sliceVertices->push_back( osg::Vec3( 0, 100, 0 ) );
sliceVertices->push_back( osg::Vec3( 0, 100, 160 ) );
sliceVertices->push_back( osg::Vec3( 160, 100, 160 ) );
sliceVertices->push_back( osg::Vec3( 160, 100, 0 ) );
sliceVertices->push_back( osg::Vec3( 80, 0, 0 ) );
sliceVertices->push_back( osg::Vec3( 80, 0, 160 ) );
sliceVertices->push_back( osg::Vec3( 80, 200, 160 ) );
sliceVertices->push_back( osg::Vec3( 80, 200, 0 ) );
sliceVertices->push_back( osg::Vec3( 0, 0, 80 ) );
sliceVertices->push_back( osg::Vec3( 0, 200, 80 ) );
sliceVertices->push_back( osg::Vec3( 160, 200, 80 ) );
sliceVertices->push_back( osg::Vec3( 160, 0, 80 ) );
sliceGeometry->setVertexArray( sliceVertices );
......
......@@ -97,6 +97,8 @@ private:
*
*/
boost::shared_ptr< WShader >m_shader;
bool m_textureAssigned;
};
#endif // WNAVIGATIONSLICEMODULE_H
......
varying vec4 VaryingTexCoord0;
uniform sampler3D tex0;
void main()
{
VaryingTexCoord0 = gl_MultiTexCoord0;
gl_Position = ftransform();
vec4 color = texture3D(tex0, VaryingTexCoord0);
if ( ( color.r + color.g + color.b ) < 0.01 )
discard;
gl_FragColor = color;
}
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