* Implemented box structuring element in GlMorphologyFilter

* Updated GlGradientVolumeGenerator to generate GL_RGB16F textures to save memory
parent f222dd65
......@@ -57,13 +57,51 @@ void main() {
out_Color = texelFetch(_texture, texel, 0);
#ifdef CUBE_ELEMENT
out_Color = FILTER_OP(out_Color, texelFetchOffset(_texture, texel, 0, ivec3(-1, -1, -1)));
out_Color = FILTER_OP(out_Color, texelFetchOffset(_texture, texel, 0, ivec3( 0, -1, -1)));
out_Color = FILTER_OP(out_Color, texelFetchOffset(_texture, texel, 0, ivec3( 1, -1, -1)));
out_Color = FILTER_OP(out_Color, texelFetchOffset(_texture, texel, 0, ivec3(-1, 0, -1)));
out_Color = FILTER_OP(out_Color, texelFetchOffset(_texture, texel, 0, ivec3( 0, 0, -1)));
out_Color = FILTER_OP(out_Color, texelFetchOffset(_texture, texel, 0, ivec3( 1, 0, -1)));
out_Color = FILTER_OP(out_Color, texelFetchOffset(_texture, texel, 0, ivec3(-1, 1, -1)));
out_Color = FILTER_OP(out_Color, texelFetchOffset(_texture, texel, 0, ivec3( 0, 1, -1)));
out_Color = FILTER_OP(out_Color, texelFetchOffset(_texture, texel, 0, ivec3( 1, 1, -1)));
out_Color = FILTER_OP(out_Color, texelFetchOffset(_texture, texel, 0, ivec3(-1, -1, 0)));
out_Color = FILTER_OP(out_Color, texelFetchOffset(_texture, texel, 0, ivec3( 0, -1, 0)));
out_Color = FILTER_OP(out_Color, texelFetchOffset(_texture, texel, 0, ivec3( 1, -1, 0)));
out_Color = FILTER_OP(out_Color, texelFetchOffset(_texture, texel, 0, ivec3(-1, 0, 0)));
out_Color = FILTER_OP(out_Color, texelFetchOffset(_texture, texel, 0, ivec3( 1, 0, 0)));
out_Color = FILTER_OP(out_Color, texelFetchOffset(_texture, texel, 0, ivec3(-1, 1, 0)));
out_Color = FILTER_OP(out_Color, texelFetchOffset(_texture, texel, 0, ivec3( 0, 1, 0)));
out_Color = FILTER_OP(out_Color, texelFetchOffset(_texture, texel, 0, ivec3( 1, 1, 0)));
out_Color = FILTER_OP(out_Color, texelFetchOffset(_texture, texel, 0, ivec3(-1, -1, 1)));
out_Color = FILTER_OP(out_Color, texelFetchOffset(_texture, texel, 0, ivec3( 0, -1, 1)));
out_Color = FILTER_OP(out_Color, texelFetchOffset(_texture, texel, 0, ivec3( 1, -1, 1)));
out_Color = FILTER_OP(out_Color, texelFetchOffset(_texture, texel, 0, ivec3(-1, 0, 1)));
out_Color = FILTER_OP(out_Color, texelFetchOffset(_texture, texel, 0, ivec3( 0, 0, 1)));
out_Color = FILTER_OP(out_Color, texelFetchOffset(_texture, texel, 0, ivec3( 1, 0, 1)));
out_Color = FILTER_OP(out_Color, texelFetchOffset(_texture, texel, 0, ivec3(-1, 1, 1)));
out_Color = FILTER_OP(out_Color, texelFetchOffset(_texture, texel, 0, ivec3( 0, 1, 1)));
out_Color = FILTER_OP(out_Color, texelFetchOffset(_texture, texel, 0, ivec3( 1, 1, 1)));
#endif
#ifdef CROSS_ELEMENT
out_Color = FILTER_OP(out_Color, texelFetchOffset(_texture, texel, 0, ivec3(-1, 0, 0)));
out_Color = FILTER_OP(out_Color, texelFetchOffset(_texture, texel, 0, ivec3( 1, 0, 0)));
out_Color = FILTER_OP(out_Color, texelFetchOffset(_texture, texel, 0, ivec3( 0, -1, 0)));
out_Color = FILTER_OP(out_Color, texelFetchOffset(_texture, texel, 0, ivec3( 0, 1, 0)));
out_Color = FILTER_OP(out_Color, texelFetchOffset(_texture, texel, 0, ivec3( 0, 0, -1)));
out_Color = FILTER_OP(out_Color, texelFetchOffset(_texture, texel, 0, ivec3( 0, 0, 1)));
#endif
}
#endif
......@@ -83,7 +83,7 @@ namespace campvis {
inputUnit.activate();
// create texture for result
tgt::Texture* resultTexture = new tgt::Texture(0, tgt::ivec3(size), GL_RGB, GL_RGB32F, GL_FLOAT, tgt::Texture::LINEAR);
tgt::Texture* resultTexture = new tgt::Texture(0, tgt::ivec3(size), GL_RGB, GL_RGB16F, GL_FLOAT, tgt::Texture::LINEAR);
resultTexture->uploadTexture();
// activate shader and bind textures
......
......@@ -41,6 +41,10 @@
#include "core/tools/stringutils.h"
namespace campvis {
GenericOption<std::string> structuringElementOptions[2] = {
GenericOption<std::string>("CROSS_ELEMENT", "Cross"),
GenericOption<std::string>("CUBE_ELEMENT", "Cube")
};
const std::string GlMorphologyFilter::loggerCat_ = "CAMPVis.modules.classification.GlMorphologyFilter";
......@@ -49,12 +53,14 @@ namespace campvis {
, p_inputImage("InputImage", "Input Image", "", DataNameProperty::READ, AbstractProcessor::INVALID_RESULT)
, p_outputImage("OutputImage", "Output Image", "GlMorphologyFilter.out", DataNameProperty::WRITE)
, p_filterOperation("FilterOperation", "Operations to Apply ([edoc]+)", "ed")
, p_structuringElement("StructuringElement", "Structuring Element", structuringElementOptions, 2, INVALID_SHADER | INVALID_RESULT)
, _erosionFilter(nullptr)
, _dilationFilter(nullptr)
{
addProperty(&p_inputImage);
addProperty(&p_outputImage);
addProperty(&p_filterOperation);
addProperty(&p_structuringElement);
}
GlMorphologyFilter::~GlMorphologyFilter() {
......@@ -64,11 +70,11 @@ namespace campvis {
void GlMorphologyFilter::init() {
VisualizationProcessor::init();
_erosionFilter = ShdrMgr.load("core/glsl/passthrough.vert", "modules/preprocessing/glsl/GlMorphologyFilter.frag", "#define FILTER_OP min\n");
_erosionFilter = ShdrMgr.load("core/glsl/passthrough.vert", "modules/preprocessing/glsl/GlMorphologyFilter.frag", generateGlslHeader("min"));
_erosionFilter->setAttributeLocation(0, "in_Position");
_erosionFilter->setAttributeLocation(1, "in_TexCoord");
_dilationFilter = ShdrMgr.load("core/glsl/passthrough.vert", "modules/preprocessing/glsl/GlMorphologyFilter.frag", "#define FILTER_OP max\n");
_dilationFilter = ShdrMgr.load("core/glsl/passthrough.vert", "modules/preprocessing/glsl/GlMorphologyFilter.frag", generateGlslHeader("max"));
_dilationFilter->setAttributeLocation(0, "in_Position");
_dilationFilter->setAttributeLocation(1, "in_TexCoord");
}
......@@ -168,4 +174,19 @@ namespace campvis {
return resultTexture;
}
void GlMorphologyFilter::updateShader() {
_erosionFilter->setHeaders(generateGlslHeader("min"));
_erosionFilter->rebuild();
_dilationFilter->setHeaders(generateGlslHeader("max"));
_dilationFilter->rebuild();
validate(INVALID_SHADER);
}
std::string GlMorphologyFilter::generateGlslHeader(const std::string& filerOp) const {
std::string toReturn = "#define FILTER_OP " + filerOp + "\n";
toReturn += "#define " + p_structuringElement.getOptionValue() + "\n";
return toReturn;
}
}
......@@ -30,6 +30,7 @@
#include "core/pipeline/abstractprocessordecorator.h"
#include "core/pipeline/visualizationprocessor.h"
#include "core/properties/datanameproperty.h"
#include "core/properties/optionproperty.h"
namespace tgt {
class Shader;
......@@ -69,10 +70,15 @@ namespace campvis {
DataNameProperty p_outputImage; ///< ID for output gradient volume
StringProperty p_filterOperation; ///< String-encoded filter operation to apply
GenericOptionProperty<std::string> p_structuringElement; ///< Structuring element to use
protected:
/// \see AbstractProcessor::updateResult
virtual void updateResult(DataContainer& dataContainer);
/// \see AbstractProcessor::updateShader
virtual void updateShader();
/// generate the GLSL header
std::string generateGlslHeader(const std::string& filerOp) const;
/**
* Applys the morphology filter \a filter to \a inputImage.
......
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