Moved PropertyAdjustmentCallback from osgvolume.cpp into osgVolume.

Updated lighting shaders.
This commit is contained in:
Robert Osfield
2009-01-20 17:41:45 +00:00
parent 0739b09519
commit a40aa3a734
8 changed files with 128 additions and 111 deletions

View File

@@ -40,6 +40,7 @@ SET(TARGET_LIBRARIES_VARS FREETYPE_LIBRARY )
LINK_INTERNAL(${LIB_NAME}
osgUtil
osgDB
osgGA
osg
OpenThreads
)

View File

@@ -71,6 +71,7 @@ void Layer::addProperty(Property* property)
{
cp = new CompositeProperty;
cp->addProperty(property);
cp->addProperty(_property.get());
_property = cp;
}
}

View File

@@ -12,6 +12,7 @@
*/
#include <osgVolume/Property>
#include <osgVolume/VolumeTile>
using namespace osgVolume;
@@ -201,3 +202,83 @@ void CollectPropertiesVisitor::apply(MaximumIntensityProjectionProperty& mip) {
void CollectPropertiesVisitor::apply(LightingProperty& lp) { _lightingProperty = &lp; }
void CollectPropertiesVisitor::apply(SampleDensityProperty& sdp) { _sampleDensityProperty = &sdp; }
void CollectPropertiesVisitor::apply(TransparencyProperty& tp) { _transparencyProperty = &tp; }
/////////////////////////////////////////////////////////////////////////////
//
// PropertyAdjustmentCallback
//
PropertyAdjustmentCallback::PropertyAdjustmentCallback()
{
_transparencyKey = 't';
_alphaFuncKey = 'a';
_sampleDensityKey = 'd';
_updateTransparency = false;
_updateAlphaCutOff = false;
_updateSampleDensity = false;
}
bool PropertyAdjustmentCallback::handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter&, osg::Object* object, osg::NodeVisitor*)
{
osgVolume::VolumeTile* tile = dynamic_cast<osgVolume::VolumeTile*>(object);
osgVolume::Layer* layer = tile ? tile->getLayer() : 0;
osgVolume::Property* property = layer ? layer->getProperty() : 0;
if (!property) return false;
osgVolume::CollectPropertiesVisitor cpv;
property->accept(cpv);
switch(ea.getEventType())
{
case(osgGA::GUIEventAdapter::MOVE):
case(osgGA::GUIEventAdapter::DRAG):
{
float v = (ea.getY()-ea.getYmin())/(ea.getYmax()-ea.getYmin());
float v2 = v*v;
float v4 = v2*v2;
if (_updateAlphaCutOff && cpv._isoProperty.valid())
{
osg::notify(osg::NOTICE)<<"Setting isoProperty to "<<v<<std::endl;
cpv._isoProperty->setValue(v);
}
if (_updateAlphaCutOff && cpv._afProperty.valid())
{
osg::notify(osg::NOTICE)<<"Setting afProperty to "<<v2<<std::endl;
cpv._afProperty->setValue(v2);
}
if (_updateTransparency && cpv._transparencyProperty.valid())
{
osg::notify(osg::NOTICE)<<"Setting transparency to "<<v2<<std::endl;
cpv._transparencyProperty->setValue(v2);
}
if (_updateSampleDensity && cpv._sampleDensityProperty.valid())
{
osg::notify(osg::NOTICE)<<"Setting sample density to "<<v4<<std::endl;
cpv._sampleDensityProperty->setValue(v4);
}
}
case(osgGA::GUIEventAdapter::KEYDOWN):
{
if (ea.getKey()=='t') _updateTransparency = true;
if (ea.getKey()=='a') _updateAlphaCutOff = true;
if (ea.getKey()=='d') _updateSampleDensity = true;
break;
}
case(osgGA::GUIEventAdapter::KEYUP):
{
if (ea.getKey()=='t') _updateTransparency = false;
if (ea.getKey()=='a') _updateAlphaCutOff = false;
if (ea.getKey()=='d') _updateSampleDensity = false;
break;
}
default:
break;
}
return false;
}

View File

@@ -104,7 +104,6 @@ void ShaderTechnique::init()
if (_volumeTile->getLayer() && !masterLocator)
{
masterLocator = _volumeTile->getLayer()->getLocator();
osg::notify(osg::NOTICE)<<"assigning locator = "<<masterLocator<<std::endl;
}
osg::Matrix matrix;
@@ -300,6 +299,8 @@ void ShaderTechnique::init()
{
if (tf)
{
osg::notify(osg::NOTICE)<<"Setting up TF path"<<std::endl;
osg::Texture1D* texture1D = new osg::Texture1D;
texture1D->setImage(tf->getImage());
texture1D->setResizeNonPowerOfTwoHint(false);

View File

@@ -11,6 +11,8 @@ char volume_lit_frag[] = "uniform sampler3D baseTexture;\n"
"{ \n"
" vec3 t0 = (texgen * vertexPos).xyz;\n"
" vec3 te = (texgen * cameraPos).xyz;\n"
" \n"
" vec3 eyeDirection = normalize(te-t0);\n"
"\n"
" if (te.x>=0.0 && te.x<=1.0 &&\n"
" te.y>=0.0 && te.y<=1.0 &&\n"

View File

@@ -83,7 +83,7 @@ char volume_lit_tf_frag[] = "uniform sampler3D baseTexture;\n"
" float v = texture3D( baseTexture, texcoord).a;\n"
" vec4 color = texture1D( tfTexture, v);\n"
"\n"
" float a = color.a;\n"
" float a = v;\n"
" float px = texture3D( baseTexture, texcoord + deltaX).a;\n"
" float py = texture3D( baseTexture, texcoord + deltaY).a;\n"
" float pz = texture3D( baseTexture, texcoord + deltaZ).a;\n"