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
......@@ -115,14 +115,6 @@ namespace campvis {
glClear(GL_COLOR_BUFFER_BIT);
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
const AbstractTransferFunction::IntensityHistogramType* ih = gtf->getIntensityHistogram();
if (ih != 0) {
......@@ -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);
......@@ -203,6 +203,8 @@ namespace campvis {
void Geometry1DTransferFunctionEditor::mousePressEvent(tgt::MouseEvent* e) {
if (_selectedGeometry != 0 && e->modifiers() & tgt::Event::CTRL) {
tbb::mutex::scoped_lock lock(_localMutex);
// add a control point on CTRL+Click
TFGeometry1D* g = _selectedGeometry->getGeometry();
std::vector<TFGeometry1D::KeyPoint>& kpts = g->getKeyPoints();
......@@ -218,6 +220,7 @@ namespace campvis {
kp._color.a = static_cast<uint8_t>(alpha * 255.f);
kpts.insert(lb, kp);
updateManipulators();
g->s_changed();
}
else {
......
......@@ -68,12 +68,12 @@ namespace campvis {
std::vector<KeyPoint>::const_iterator a = _keyPoints.begin();
std::vector<KeyPoint>::const_iterator b = _keyPoints.begin()+1;
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;
glVertex2f(a->_position, 0.f);
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;
glVertex2f(b->_position, y);
glVertex2f(b->_position, 0.f);
......
......@@ -33,11 +33,16 @@
#include "core/properties/propertycollection.h"
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"*/)
: AbstractProcessorDecorator()
, _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))
, _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))
......@@ -46,6 +51,7 @@ namespace campvis {
, _attenuation("Attenuation", "Attenuation Factors", tgt::vec3(0.f), tgt::vec3(0.f), tgt::vec3(1.f))
, _lightUniformName(lightUniformName)
{
_gradientMethod.setValue(1);
}
ProcessorDecoratorShading::~ProcessorDecoratorShading() {
......@@ -53,7 +59,7 @@ namespace campvis {
void ProcessorDecoratorShading::addProperties(HasPropertyCollection* propCollection) {
propCollection->addProperty(&_enableShading);
propCollection->addProperty(&_centralDifferences);
propCollection->addProperty(&_gradientMethod);
propCollection->addProperty(&_lightPosition);
propCollection->addProperty(&_ambientColor);
propCollection->addProperty(&_diffuseColor);
......@@ -76,10 +82,21 @@ namespace campvis {
std::string toReturn;
if (_enableShading.getValue())
toReturn.append("#define ENABLE_SHADING\n");
if (_centralDifferences.getValue())
toReturn.append("#define computeGradient(tex, texParams,texCoords) computeGradientFilteredCentralDifferences(tex, texParams, texCoords)\n");
else
switch (_gradientMethod.getOptionValue()) {
case ForwardDifferences :
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;
}
......
......@@ -32,14 +32,21 @@
#include "tgt/textureunit.h"
#include "core/pipeline/abstractprocessordecorator.h"
#include "core/properties/datanameproperty.h"
#include "core/properties/genericproperty.h"
#include "core/properties/floatingpointproperty.h"
#include "core/properties/genericproperty.h"
#include "core/properties/optionproperty.h"
namespace campvis {
class ProcessorDecoratorShading : public AbstractProcessorDecorator {
public:
/// Method for online-calculating gradients
enum GradientMethod {
ForwardDifferences,
CentralDifferences,
FilteredCentralDifferences
};
explicit ProcessorDecoratorShading(const std::string& lightUniformName = "_lightSource");
virtual ~ProcessorDecoratorShading();
......@@ -51,7 +58,7 @@ namespace campvis {
std::string generateHeader() const;
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 _ambientColor; ///< Ambient light color
Vec3Property _diffuseColor; ///< Diffuse light color
......
......@@ -67,6 +67,7 @@ namespace campvis {
tbb::spin_mutex::scoped_lock lock(_localMutex);
_sharedProperties.insert(prop);
s_changed.connect(this, &AbstractProperty::onChanged);
}
void AbstractProperty::removeSharedProperty(AbstractProperty* prop) {
......@@ -104,4 +105,11 @@ namespace campvis {
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 {
* \todo Add PropertyWidgets, add clone()?
* Think about a reasonable locking mechanism and implement that
*/
class AbstractProperty {
class AbstractProperty : public sigslot::has_slots<> {
public:
/**
* Creates a new AbstractProperty
......@@ -155,6 +155,8 @@ namespace campvis {
protected:
void onChanged(const AbstractProperty* prop);
// DO NOT REMOVE THE CONSTNESS OF _name. PropertyCollection relies on it!
const std::string _name; ///< Property name (unchangable on purpose!)
std::string _title; ///< Property title (e.g. used for GUI)
......
......@@ -39,7 +39,7 @@ namespace campvis {
/**
* \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:
/**
* Creates a new TransferFunctionProperty
......
......@@ -84,6 +84,9 @@ const float SAMPLING_BASE_INTERVAL_RCP = 200.0;
vec4 performRaycasting(in vec3 entryPoint, in vec3 exitPoint, in vec2 texCoords) {
vec4 result = vec4(0.0);
float firstHitT = -1.0;
#ifdef ENABLE_ADAPTIVE_STEPSIZE
float samplingRateCompensationMultiplier = 1.0;
#endif
// calculate ray parameters
vec3 direction = exitPoint.rgb - entryPoint.rgb;
......@@ -169,8 +172,13 @@ vec4 performRaycasting(in vec3 entryPoint, in vec3 exitPoint, in vec2 texCoords)
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));
#endif
// 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);
#endif
result.rgb = mix(color.rgb, result.rgb, result.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)
t = tend;
}
// advance to the next evaluation point along the ray
#ifdef ENABLE_ADAPTIVE_STEPSIZE
samplingRateCompensationMultiplier = (_inVoid ? 1.0 : 0.25);
t += _samplingStepSize * (_inVoid ? 1.0 : 0.125);
#else
t += _samplingStepSize;
#endif
......
......@@ -53,7 +53,6 @@ namespace campvis {
, _raycaster(viewportSizeProp)
{
addProperty(&p_inputVolume);
// addProperty(&p_camera);
addProperty(&_raycaster.p_transferFunction);
addProperty(&p_outputImage);
......@@ -118,10 +117,6 @@ namespace campvis {
_eepGenerator.deinit();
_raycaster.deinit();
removeProperty(&_raycaster.p_transferFunction);
removeProperty(&_raycaster.p_samplingRate);
removeProperty(_raycaster.getProperty("CentralDifferences"));
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