Currently job artifacts in CI/CD pipelines on LRZ GitLab never expire. Starting from Wed 26.1.2022 the default expiration time will be 30 days (GitLab default). Currently existing artifacts in already completed jobs will not be affected by the change. The latest artifacts for all jobs in the latest successful pipelines will be kept. More information: https://gitlab.lrz.de/help/user/admin_area/settings/continuous_integration.html#default-artifacts-expiration

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

cleaned up GlReduction interface

parent 18b72370
......@@ -45,13 +45,5 @@ void main() {
vec4 c = texelFetch(_texture, texel + ivec2(0, 1), 0);
vec4 d = texelFetch(_texture, texel + ivec2(1, 1), 0);
//vec4 a = texture(_texture, tmp);
//vec4 b = texture(_texture, texel + vec2(_textureParams._sizeRCP.x, 0));
//vec4 c = texture(_texture, texel + vec2(0, _textureParams._sizeRCP.y));
//vec4 d = texture(_texture, texel + vec2(_textureParams._sizeRCP.x, _textureParams._sizeRCP.y));
//out_Color = max(a, max(b, max(c, d)));
out_Color = a+b+c+d;
//out_Color = vec4(texel, 0.0, 1.0);
//out_Color = vec4(ex_TexCoord, 1.0);
out_Color = REDUCTION_OP(a, b, c, d);
}
......@@ -48,12 +48,12 @@ namespace campvis {
const std::string GlReduction::loggerCat_ = "CAMPVis.modules.registration.GlReduction";
GlReduction::GlReduction()
: _shader(0)
GlReduction::GlReduction(ReductionOperator reductionOperator)
: _reductionOperator(reductionOperator)
, _shader(0)
, _fbo(0)
, _renderQuad(0)
{
_shader = ShdrMgr.loadSeparate("core/glsl/passthrough.vert", "core/glsl/tools/glreduction.frag", "", false);
_shader = ShdrMgr.loadSeparate("core/glsl/passthrough.vert", "core/glsl/tools/glreduction.frag", generateGlslHeader(_reductionOperator), false);
if (_shader == 0) {
LERROR("Could not load Shader for OpenGL reduction. Reduction will not work!");
return;
......@@ -100,7 +100,6 @@ namespace campvis {
return toReturn;
}
//tgtAssert(texture->getNumChannels() == 1, "Reduction of images with more than one channel currently not implemented! Somebody was too lazy (or stressed - deadline was close) to do that...");
tgtAssert(texture->getDimensions().z == 1, "Reduction of 3D images not yet implemented! Somebody was too lazy (or stressed - deadline was close) to do that...");
std::vector<float> readBackBuffer;
......@@ -116,14 +115,14 @@ namespace campvis {
tgt::TextureUnit inputUnit;
// create temporary textures
tgt::Texture* tempTextures[2];
for (size_t i = 0; i < 2; ++i) {
//_tempTextures[i] = new tgt::Texture(0, tgt::ivec3(currentSize, 1), GL_RED, GL_R32F, GL_FLOAT, tgt::Texture::NEAREST);
_tempTextures[i] = new tgt::Texture(0, tgt::ivec3(currentSize, 1), GL_RGBA, GL_RGBA32F, GL_FLOAT, tgt::Texture::NEAREST);
_tempTextures[i]->uploadTexture();
_tempTextures[i]->setWrapping(tgt::Texture::CLAMP);
tempTextures[i] = new tgt::Texture(0, tgt::ivec3(currentSize, 1), GL_RGBA, GL_RGBA32F, GL_FLOAT, tgt::Texture::NEAREST);
tempTextures[i]->uploadTexture();
tempTextures[i]->setWrapping(tgt::Texture::CLAMP);
}
_readTex = 0;
_writeTex = 1;
size_t readTex = 0;
size_t writeTex = 1;
// create and initialize FBO
_fbo = new tgt::FramebufferObject();
......@@ -132,7 +131,7 @@ namespace campvis {
// perform first reduction step outside:
_shader->activate();
_fbo->attachTexture(_tempTextures[_readTex]);
_fbo->attachTexture(tempTextures[readTex]);
_shader->setIgnoreUniformLocationError(true);
inputUnit.activate();
......@@ -152,8 +151,8 @@ namespace campvis {
while (currentSize.x > 1 || currentSize.y > 1) {
reduceSizes(currentSize, texCoordMultiplier);
_fbo->attachTexture(_tempTextures[_writeTex]);
_tempTextures[_readTex]->bind();
_fbo->attachTexture(tempTextures[writeTex]);
tempTextures[readTex]->bind();
glViewport(0, 0, currentSize.x, currentSize.y);
_shader->setUniform("_texCoordsMultiplier", texCoordMultiplier);
......@@ -161,15 +160,15 @@ namespace campvis {
LGL_ERROR;
//_fbo->detachTexture(GL_COLOR_ATTACHMENT0);
std::swap(_writeTex, _readTex);
std::swap(writeTex, readTex);
}
_shader->deactivate();
// read back stuff
GLenum readBackFormat = _tempTextures[_readTex]->getFormat();
size_t channels = _tempTextures[_readTex]->getNumChannels();
GLenum readBackFormat = tempTextures[readTex]->getFormat();
size_t channels = tempTextures[readTex]->getNumChannels();
toReturn.resize(currentSize.x * currentSize.y * channels);
glReadBuffer(GL_COLOR_ATTACHMENT0);
glReadPixels(0, 0, currentSize.x, currentSize.y, readBackFormat, GL_FLOAT, &toReturn.front());
......@@ -181,8 +180,8 @@ namespace campvis {
delete _fbo;
_fbo = 0;
delete _tempTextures[0];
delete _tempTextures[1];
delete tempTextures[0];
delete tempTextures[1];
LGL_ERROR;
return toReturn;
......@@ -200,4 +199,25 @@ namespace campvis {
}
std::string GlReduction::generateGlslHeader(ReductionOperator reductionOperator) {
switch (reductionOperator) {
case MIN:
return "#define REDUCTION_OP(a, b, c, d) min(a, min(b, min(c, d)))";
break;
case MAX:
return "#define REDUCTION_OP(a, b, c, d) max(a, max(b, max(c, d)))";
break;
case PLUS:
return "#define REDUCTION_OP(a, b, c, d) a+b+c+d";
break;
case MULTIPLICATION:
return "#define REDUCTION_OP(a, b, c, d) a*b*c*d";
break;
default:
tgtAssert(false, "Should not reach this, wrong enum value?");
return "";
break;
}
}
}
\ No newline at end of file
......@@ -49,18 +49,45 @@ namespace campvis {
/**
* Class performing a reduction of 2D image data using OpenGL.
* TODO: implement 3D reduction - shouldn't be that difficult
* \note All methods need to be called from a valid OpenGL context.
*/
class GlReduction {
public:
GlReduction();
~GlReduction();
/// Operation to be performed by reduction
enum ReductionOperator {
MIN, ///< Minimum
MAX, ///< Maximum
PLUS, ///< Sum (plus)
MULTIPLICATION ///< Product (multiplication)
};
/**
* Constructor
* \param reductionOperator Operation to be performed by reduction
*/
GlReduction(ReductionOperator reductionOperator);
/**
* Destructor
*/
~GlReduction();
/**
* Performs the reduction on the given image.
* \note Image must be two-dimensional!
* \note Reduction will be performed on a copy, \a image will not change.
* \param image Pointer to ImageData to perform reduction on, must be two-dimensional.
* \return A vector of floats containing the reduction results for each channel of the input image.
*/
std::vector<float> reduce(const ImageData* image);
/**
* Performs the reduction on the given OpenGL texture.
* \note Image must be two-dimensional!
* \note Reduction will be performed on a copy, \a texture will not change.
* \param image Pointer to a texture to perform reduction on, must be two-dimensional.
* \return A vector of floats containing the reduction results for each channel of the input texture.
*/
std::vector<float> reduce(const tgt::Texture* texture);
......@@ -72,13 +99,17 @@ namespace campvis {
*/
static void reduceSizes(tgt::ivec2& currentSize, tgt::vec2& texCoordMultiplier);
size_t _readTex;
size_t _writeTex;
/**
* Generates the GLSL header corresponding to the given reduction operator.
* \param reductionOperator Operation to be performed by reduction
* \return A std::string with the corresponding GLSL header.
*/
static std::string generateGlslHeader(ReductionOperator reductionOperator);
tgt::Shader* _shader;
tgt::FramebufferObject* _fbo;
tgt::Texture* _tempTextures[2];
FaceGeometry* _renderQuad;
ReductionOperator _reductionOperator; ///< Operation to be performed by reduction
tgt::Shader* _shader; ///< OpenGL shader performing the reduction
tgt::FramebufferObject* _fbo; ///< FBO performing the reduction
const static std::string loggerCat_;
};
......
......@@ -128,7 +128,7 @@ namespace campvis {
_differenceShader->setAttributeLocation(0, "in_Position");
_differenceShader->setAttributeLocation(1, "in_TexCoord");
_glr = new GlReduction();
_glr = new GlReduction(GlReduction::PLUS);
}
void SimilarityMeasure::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