Commit e7b11bfa authored by Christian Schulte zu Berge's avatar Christian Schulte zu Berge
Browse files

various fixes/improvement related to the raycasting processors:

 * fixed 1D geometry TF editor
 * introduced OptionProperty to specify gradient computation mode
 * added s_changed signal of properties also being propagated to its shared properties
 * fixed sampling rate compensation when using adaptive sampling in simpleraycaster.frag
parent 5d09be1f
...@@ -114,15 +114,7 @@ namespace campvis { ...@@ -114,15 +114,7 @@ namespace campvis {
glClearColor(1.f, 1.f, 1.f, 1.f); glClearColor(1.f, 1.f, 1.f, 1.f);
glClear(GL_COLOR_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT);
LGL_ERROR; LGL_ERROR;
// renderIntoEditor TF geometries
{
tbb::mutex::scoped_lock lock(_localMutex);
for (std::vector<TFGeometry1D*>::const_iterator it = geometries.begin(); it != geometries.end(); ++it) {
(*it)->renderIntoEditor();
}
}
// render histogram if existent // render histogram if existent
const AbstractTransferFunction::IntensityHistogramType* ih = gtf->getIntensityHistogram(); const AbstractTransferFunction::IntensityHistogramType* ih = gtf->getIntensityHistogram();
if (ih != 0) { if (ih != 0) {
...@@ -160,6 +152,14 @@ namespace campvis { ...@@ -160,6 +152,14 @@ namespace campvis {
} }
} }
// render TF geometries
{
tbb::mutex::scoped_lock lock(_localMutex);
for (std::vector<TFGeometry1D*>::const_iterator it = geometries.begin(); it != geometries.end(); ++it) {
(*it)->renderIntoEditor();
}
}
{ {
tbb::mutex::scoped_lock lock(_localMutex); tbb::mutex::scoped_lock lock(_localMutex);
...@@ -203,6 +203,8 @@ namespace campvis { ...@@ -203,6 +203,8 @@ namespace campvis {
void Geometry1DTransferFunctionEditor::mousePressEvent(tgt::MouseEvent* e) { void Geometry1DTransferFunctionEditor::mousePressEvent(tgt::MouseEvent* e) {
if (_selectedGeometry != 0 && e->modifiers() & tgt::Event::CTRL) { if (_selectedGeometry != 0 && e->modifiers() & tgt::Event::CTRL) {
tbb::mutex::scoped_lock lock(_localMutex);
// add a control point on CTRL+Click // add a control point on CTRL+Click
TFGeometry1D* g = _selectedGeometry->getGeometry(); TFGeometry1D* g = _selectedGeometry->getGeometry();
std::vector<TFGeometry1D::KeyPoint>& kpts = g->getKeyPoints(); std::vector<TFGeometry1D::KeyPoint>& kpts = g->getKeyPoints();
...@@ -218,6 +220,7 @@ namespace campvis { ...@@ -218,6 +220,7 @@ namespace campvis {
kp._color.a = static_cast<uint8_t>(alpha * 255.f); kp._color.a = static_cast<uint8_t>(alpha * 255.f);
kpts.insert(lb, kp); kpts.insert(lb, kp);
updateManipulators(); updateManipulators();
g->s_changed(); g->s_changed();
} }
else { else {
......
...@@ -68,12 +68,12 @@ namespace campvis { ...@@ -68,12 +68,12 @@ namespace campvis {
std::vector<KeyPoint>::const_iterator a = _keyPoints.begin(); std::vector<KeyPoint>::const_iterator a = _keyPoints.begin();
std::vector<KeyPoint>::const_iterator b = _keyPoints.begin()+1; std::vector<KeyPoint>::const_iterator b = _keyPoints.begin()+1;
for (/* already inited */; b != _keyPoints.end(); ++a, ++b) { for (/* already inited */; b != _keyPoints.end(); ++a, ++b) {
glColor4ubv(a->_color.elem); glColor4ub(a->_color.r, a->_color.g, a->_color.b, 144);
float y = static_cast<float>(a->_color.a) / 255.f; float y = static_cast<float>(a->_color.a) / 255.f;
glVertex2f(a->_position, 0.f); glVertex2f(a->_position, 0.f);
glVertex2f(a->_position, y); glVertex2f(a->_position, y);
glColor4ubv(b->_color.elem); glColor4ub(b->_color.r, b->_color.g, b->_color.b, 144);
y = static_cast<float>(b->_color.a) / 255.f; y = static_cast<float>(b->_color.a) / 255.f;
glVertex2f(b->_position, y); glVertex2f(b->_position, y);
glVertex2f(b->_position, 0.f); glVertex2f(b->_position, 0.f);
......
...@@ -33,11 +33,16 @@ ...@@ -33,11 +33,16 @@
#include "core/properties/propertycollection.h" #include "core/properties/propertycollection.h"
namespace campvis { namespace campvis {
static const GenericOption<ProcessorDecoratorShading::GradientMethod> gradientOptions[3] = {
GenericOption<ProcessorDecoratorShading::GradientMethod>("Forward", "Forward Differences", ProcessorDecoratorShading::ForwardDifferences),
GenericOption<ProcessorDecoratorShading::GradientMethod>("Central", "Central Differences", ProcessorDecoratorShading::CentralDifferences),
GenericOption<ProcessorDecoratorShading::GradientMethod>("FilteredCentral", "Filtered Central Differences", ProcessorDecoratorShading::FilteredCentralDifferences)
};
ProcessorDecoratorShading::ProcessorDecoratorShading(const std::string& lightUniformName /*= "_lightSource"*/) ProcessorDecoratorShading::ProcessorDecoratorShading(const std::string& lightUniformName /*= "_lightSource"*/)
: AbstractProcessorDecorator() : AbstractProcessorDecorator()
, _enableShading("EnableShading", "Enable Shading", true, AbstractProcessor::INVALID_SHADER | AbstractProcessor::INVALID_RESULT) , _enableShading("EnableShading", "Enable Shading", true, AbstractProcessor::INVALID_SHADER | AbstractProcessor::INVALID_RESULT)
, _centralDifferences("CentralDifferences", "Use Central instead of Forward Differences", false, AbstractProcessor::INVALID_SHADER | AbstractProcessor::INVALID_RESULT) , _gradientMethod("GradientMethod", "Gradient Computation Method", gradientOptions, 3, AbstractProcessor::INVALID_SHADER | AbstractProcessor::INVALID_RESULT)
, _lightPosition("LightPosition", "Light Position", tgt::vec3(-100.f), tgt::vec3(-500.f), tgt::vec3(500.f), tgt::vec3(1.f)) , _lightPosition("LightPosition", "Light Position", tgt::vec3(-100.f), tgt::vec3(-500.f), tgt::vec3(500.f), tgt::vec3(1.f))
, _ambientColor("AmbientColor", "Ambient Light Color", tgt::vec3(0.4f), tgt::vec3(0.f), tgt::vec3(1.f)) , _ambientColor("AmbientColor", "Ambient Light Color", tgt::vec3(0.4f), tgt::vec3(0.f), tgt::vec3(1.f))
, _diffuseColor("DiffuseColor", "Diffuse Light Color", tgt::vec3(0.75f), tgt::vec3(0.f), tgt::vec3(1.f)) , _diffuseColor("DiffuseColor", "Diffuse Light Color", tgt::vec3(0.75f), tgt::vec3(0.f), tgt::vec3(1.f))
...@@ -46,6 +51,7 @@ namespace campvis { ...@@ -46,6 +51,7 @@ namespace campvis {
, _attenuation("Attenuation", "Attenuation Factors", tgt::vec3(0.f), tgt::vec3(0.f), tgt::vec3(1.f)) , _attenuation("Attenuation", "Attenuation Factors", tgt::vec3(0.f), tgt::vec3(0.f), tgt::vec3(1.f))
, _lightUniformName(lightUniformName) , _lightUniformName(lightUniformName)
{ {
_gradientMethod.setValue(1);
} }
ProcessorDecoratorShading::~ProcessorDecoratorShading() { ProcessorDecoratorShading::~ProcessorDecoratorShading() {
...@@ -53,7 +59,7 @@ namespace campvis { ...@@ -53,7 +59,7 @@ namespace campvis {
void ProcessorDecoratorShading::addProperties(HasPropertyCollection* propCollection) { void ProcessorDecoratorShading::addProperties(HasPropertyCollection* propCollection) {
propCollection->addProperty(&_enableShading); propCollection->addProperty(&_enableShading);
propCollection->addProperty(&_centralDifferences); propCollection->addProperty(&_gradientMethod);
propCollection->addProperty(&_lightPosition); propCollection->addProperty(&_lightPosition);
propCollection->addProperty(&_ambientColor); propCollection->addProperty(&_ambientColor);
propCollection->addProperty(&_diffuseColor); propCollection->addProperty(&_diffuseColor);
...@@ -76,10 +82,21 @@ namespace campvis { ...@@ -76,10 +82,21 @@ namespace campvis {
std::string toReturn; std::string toReturn;
if (_enableShading.getValue()) if (_enableShading.getValue())
toReturn.append("#define ENABLE_SHADING\n"); toReturn.append("#define ENABLE_SHADING\n");
if (_centralDifferences.getValue())
toReturn.append("#define computeGradient(tex, texParams,texCoords) computeGradientFilteredCentralDifferences(tex, texParams, texCoords)\n"); switch (_gradientMethod.getOptionValue()) {
else case ForwardDifferences :
toReturn.append("#define computeGradient(tex, texParams,texCoords) computeGradientForwardDifferences(tex, texParams, texCoords)\n"); toReturn.append("#define computeGradient(tex, texParams,texCoords) computeGradientForwardDifferences(tex, texParams, texCoords)\n");
break;
case CentralDifferences :
toReturn.append("#define computeGradient(tex, texParams,texCoords) computeGradientCentralDifferences(tex, texParams, texCoords)\n");
break;
case FilteredCentralDifferences :
toReturn.append("#define computeGradient(tex, texParams,texCoords) computeGradientFilteredCentralDifferences(tex, texParams, texCoords)\n");
break;
default:
tgtAssert(false, "Invalid enum!");
break;
}
return toReturn; return toReturn;
} }
......
...@@ -32,14 +32,21 @@ ...@@ -32,14 +32,21 @@
#include "tgt/textureunit.h" #include "tgt/textureunit.h"
#include "core/pipeline/abstractprocessordecorator.h" #include "core/pipeline/abstractprocessordecorator.h"
#include "core/properties/datanameproperty.h"
#include "core/properties/genericproperty.h"
#include "core/properties/floatingpointproperty.h" #include "core/properties/floatingpointproperty.h"
#include "core/properties/genericproperty.h"
#include "core/properties/optionproperty.h"
namespace campvis { namespace campvis {
class ProcessorDecoratorShading : public AbstractProcessorDecorator { class ProcessorDecoratorShading : public AbstractProcessorDecorator {
public: public:
/// Method for online-calculating gradients
enum GradientMethod {
ForwardDifferences,
CentralDifferences,
FilteredCentralDifferences
};
explicit ProcessorDecoratorShading(const std::string& lightUniformName = "_lightSource"); explicit ProcessorDecoratorShading(const std::string& lightUniformName = "_lightSource");
virtual ~ProcessorDecoratorShading(); virtual ~ProcessorDecoratorShading();
...@@ -51,7 +58,7 @@ namespace campvis { ...@@ -51,7 +58,7 @@ namespace campvis {
std::string generateHeader() const; std::string generateHeader() const;
BoolProperty _enableShading; ///< Flag whether to enable shading; BoolProperty _enableShading; ///< Flag whether to enable shading;
BoolProperty _centralDifferences; ///< Use central instead of forward-differences for gradient calculation GenericOptionProperty<GradientMethod> _gradientMethod; ///< Method for calculating the gradients
Vec3Property _lightPosition; ///< Light position Vec3Property _lightPosition; ///< Light position
Vec3Property _ambientColor; ///< Ambient light color Vec3Property _ambientColor; ///< Ambient light color
Vec3Property _diffuseColor; ///< Diffuse light color Vec3Property _diffuseColor; ///< Diffuse light color
......
...@@ -67,6 +67,7 @@ namespace campvis { ...@@ -67,6 +67,7 @@ namespace campvis {
tbb::spin_mutex::scoped_lock lock(_localMutex); tbb::spin_mutex::scoped_lock lock(_localMutex);
_sharedProperties.insert(prop); _sharedProperties.insert(prop);
s_changed.connect(this, &AbstractProperty::onChanged);
} }
void AbstractProperty::removeSharedProperty(AbstractProperty* prop) { void AbstractProperty::removeSharedProperty(AbstractProperty* prop) {
...@@ -104,4 +105,11 @@ namespace campvis { ...@@ -104,4 +105,11 @@ namespace campvis {
s_visibilityChanged(this); s_visibilityChanged(this);
} }
void AbstractProperty::onChanged(const AbstractProperty* prop) {
//tbb::spin_mutex::scoped_lock lock(_localMutex);
for (std::set<AbstractProperty*>::iterator it = _sharedProperties.begin(); it != _sharedProperties.end(); ++it) {
(*it)->s_changed(prop);
}
}
} }
...@@ -46,7 +46,7 @@ namespace campvis { ...@@ -46,7 +46,7 @@ namespace campvis {
* \todo Add PropertyWidgets, add clone()? * \todo Add PropertyWidgets, add clone()?
* Think about a reasonable locking mechanism and implement that * Think about a reasonable locking mechanism and implement that
*/ */
class AbstractProperty { class AbstractProperty : public sigslot::has_slots<> {
public: public:
/** /**
* Creates a new AbstractProperty * Creates a new AbstractProperty
...@@ -154,6 +154,8 @@ namespace campvis { ...@@ -154,6 +154,8 @@ namespace campvis {
sigslot::signal1<const AbstractProperty*> s_visibilityChanged; sigslot::signal1<const AbstractProperty*> s_visibilityChanged;
protected: protected:
void onChanged(const AbstractProperty* prop);
// DO NOT REMOVE THE CONSTNESS OF _name. PropertyCollection relies on it! // DO NOT REMOVE THE CONSTNESS OF _name. PropertyCollection relies on it!
const std::string _name; ///< Property name (unchangable on purpose!) const std::string _name; ///< Property name (unchangable on purpose!)
......
...@@ -39,7 +39,7 @@ namespace campvis { ...@@ -39,7 +39,7 @@ namespace campvis {
/** /**
* \todo Implement correct behavior if the TF changes during locked property state. * \todo Implement correct behavior if the TF changes during locked property state.
*/ */
class TransferFunctionProperty : public AbstractProperty, public sigslot::has_slots<> { class TransferFunctionProperty : public AbstractProperty {
public: public:
/** /**
* Creates a new TransferFunctionProperty * Creates a new TransferFunctionProperty
......
...@@ -84,6 +84,9 @@ const float SAMPLING_BASE_INTERVAL_RCP = 200.0; ...@@ -84,6 +84,9 @@ const float SAMPLING_BASE_INTERVAL_RCP = 200.0;
vec4 performRaycasting(in vec3 entryPoint, in vec3 exitPoint, in vec2 texCoords) { vec4 performRaycasting(in vec3 entryPoint, in vec3 exitPoint, in vec2 texCoords) {
vec4 result = vec4(0.0); vec4 result = vec4(0.0);
float firstHitT = -1.0; float firstHitT = -1.0;
#ifdef ENABLE_ADAPTIVE_STEPSIZE
float samplingRateCompensationMultiplier = 1.0;
#endif
// calculate ray parameters // calculate ray parameters
vec3 direction = exitPoint.rgb - entryPoint.rgb; vec3 direction = exitPoint.rgb - entryPoint.rgb;
...@@ -169,8 +172,13 @@ vec4 performRaycasting(in vec3 entryPoint, in vec3 exitPoint, in vec2 texCoords) ...@@ -169,8 +172,13 @@ vec4 performRaycasting(in vec3 entryPoint, in vec3 exitPoint, in vec2 texCoords)
vec3 gradient = computeGradient(_volume, _volumeTextureParams, samplePosition); vec3 gradient = computeGradient(_volume, _volumeTextureParams, samplePosition);
color.rgb = calculatePhongShading(textureToWorld(_volumeTextureParams, samplePosition).xyz, _lightSource, _cameraPosition, gradient, color.rgb, color.rgb, vec3(1.0, 1.0, 1.0)); color.rgb = calculatePhongShading(textureToWorld(_volumeTextureParams, samplePosition).xyz, _lightSource, _cameraPosition, gradient, color.rgb, color.rgb, vec3(1.0, 1.0, 1.0));
#endif #endif
// accomodate for variable sampling rates // accomodate for variable sampling rates
#ifdef ENABLE_ADAPTIVE_STEPSIZE
color.a = 1.0 - pow(1.0 - color.a, _samplingStepSize * samplingRateCompensationMultiplier * SAMPLING_BASE_INTERVAL_RCP);
#else
color.a = 1.0 - pow(1.0 - color.a, _samplingStepSize * SAMPLING_BASE_INTERVAL_RCP); color.a = 1.0 - pow(1.0 - color.a, _samplingStepSize * SAMPLING_BASE_INTERVAL_RCP);
#endif
result.rgb = mix(color.rgb, result.rgb, result.a); result.rgb = mix(color.rgb, result.rgb, result.a);
result.a = result.a + (1.0 -result.a) * color.a; result.a = result.a + (1.0 -result.a) * color.a;
} }
...@@ -188,8 +196,11 @@ vec4 performRaycasting(in vec3 entryPoint, in vec3 exitPoint, in vec2 texCoords) ...@@ -188,8 +196,11 @@ vec4 performRaycasting(in vec3 entryPoint, in vec3 exitPoint, in vec2 texCoords)
t = tend; t = tend;
} }
// advance to the next evaluation point along the ray
#ifdef ENABLE_ADAPTIVE_STEPSIZE #ifdef ENABLE_ADAPTIVE_STEPSIZE
samplingRateCompensationMultiplier = (_inVoid ? 1.0 : 0.25);
t += _samplingStepSize * (_inVoid ? 1.0 : 0.125); t += _samplingStepSize * (_inVoid ? 1.0 : 0.125);
#else #else
t += _samplingStepSize; t += _samplingStepSize;
#endif #endif
......
...@@ -53,7 +53,6 @@ namespace campvis { ...@@ -53,7 +53,6 @@ namespace campvis {
, _raycaster(viewportSizeProp) , _raycaster(viewportSizeProp)
{ {
addProperty(&p_inputVolume); addProperty(&p_inputVolume);
// addProperty(&p_camera);
addProperty(&_raycaster.p_transferFunction); addProperty(&_raycaster.p_transferFunction);
addProperty(&p_outputImage); addProperty(&p_outputImage);
...@@ -118,10 +117,6 @@ namespace campvis { ...@@ -118,10 +117,6 @@ namespace campvis {
_eepGenerator.deinit(); _eepGenerator.deinit();
_raycaster.deinit(); _raycaster.deinit();
removeProperty(&_raycaster.p_transferFunction);
removeProperty(&_raycaster.p_samplingRate);
removeProperty(_raycaster.getProperty("CentralDifferences"));
VisualizationProcessor::deinit(); VisualizationProcessor::deinit();
} }
......
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