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 9436df53 authored by Declara Denis's avatar Declara Denis Committed by Christian Schulte zu Berge
Browse files

Initial effort to support 2D and 3D textures in GlImageResampler

parent 063265f4
......@@ -25,14 +25,27 @@
in vec3 ex_TexCoord;
out vec4 out_Color;
#include "tools/gradient.frag"
#ifdef GLRESAMPLER_3D
#include "tools/texture3d.frag"
uniform sampler3D _texture;
uniform TextureParameters3D _textureParams;
uniform float _zTexCoord;
#endif
#ifdef GLRESAMPLER_2D
#include "tools/texture2d.frag"
uniform sampler2D _texture;
uniform TextureParameters2D _textureParams;
#endif
void main() {
out_Color = texture(_texture, vec3(ex_TexCoord.xy, _zTexCoord));
#ifdef GLRESAMPLER_3D
vec4 sample = texture(_texture, vec3(ex_TexCoord.xy, _zTexCoord));
#endif
#ifdef GLRESAMPLER_2D
vec4 sample = texture(_texture, ex_TexCoord.xy);
#endif
out_Color = sample;
}
......@@ -45,7 +45,8 @@ namespace campvis {
, p_outputImage("OutputImage", "Output Image", "GlImageResampler.out", DataNameProperty::WRITE)
, p_resampleScale("ResampleScale", "Resampling Scale", .5f, .01f, 10.f)
, p_targetSize("TargetSize", "Size of Resampled Image", cgt::ivec3(128), cgt::ivec3(1), cgt::ivec3(1024))
, _shader(0)
, _shader2D(0)
, _shader3D(0)
{
addProperty(p_inputImage, INVALID_RESULT | INVALID_PROPERTIES);
addProperty(p_outputImage);
......@@ -60,13 +61,18 @@ namespace campvis {
void GlImageResampler::init() {
VisualizationProcessor::init();
_shader = ShdrMgr.load("core/glsl/passthrough.vert", "modules/preprocessing/glsl/glimageresampler.frag", "");
_shader->setAttributeLocation(0, "in_Position");
_shader->setAttributeLocation(1, "in_TexCoord");
_shader2D = ShdrMgr.load("core/glsl/passthrough.vert", "modules/preprocessing/glsl/glimageresampler.frag", "#define GLRESAMPLER_3D\n");
_shader2D->setAttributeLocation(0, "in_Position");
_shader2D->setAttributeLocation(1, "in_TexCoord");
_shader3D = ShdrMgr.load("core/glsl/passthrough.vert", "modules/preprocessing/glsl/glimageresampler.frag", "#define GLRESAMPLER_2D\n");
_shader3D->setAttributeLocation(0, "in_Position");
_shader3D->setAttributeLocation(1, "in_TexCoord");
}
void GlImageResampler::deinit() {
ShdrMgr.dispose(_shader);
ShdrMgr.dispose(_shader2D);
ShdrMgr.dispose(_shader3D);
VisualizationProcessor::deinit();
}
......@@ -76,34 +82,46 @@ namespace campvis {
if (img != 0) {
cgt::vec3 originalSize(img->getSize());
const cgt::ivec3& resampledSize = p_targetSize.getValue();
bool isTexture2D = img->getParent()->getDimensionality() == 2;
// 2D textures should not be scaled along the z axis
if (isTexture2D) {
resampledSize.z = 1;
}
cgt::TextureUnit inputUnit;
inputUnit.activate();
// create texture for result
cgt::Texture* resultTexture = new cgt::Texture(GL_TEXTURE_3D, resampledSize, img->getTexture()->getInternalFormat(), cgt::Texture::LINEAR);
cgt::Texture* resultTexture = new cgt::Texture(isTexture2D ? GL_TEXTURE_2D : GL_TEXTURE_3D, resampledSize, img->getTexture()->getInternalFormat(), cgt::Texture::LINEAR);
// activate shader and bind textures
_shader->activate();
img->bind(_shader, inputUnit);
// Select the right shader for the 2D and 3D case
cgt::Shader *shader = isTexture2D ? _shader2D : _shader3D;
// activate shader and bind textures
shader->activate();
img->bind(shader, inputUnit);
// activate FBO and attach texture
_fbo->activate();
glViewport(0, 0, static_cast<GLsizei>(resampledSize.x), static_cast<GLsizei>(resampledSize.y));
// render quad to compute difference measure by shader
for (int z = 0; z < resampledSize.z; ++z) {
float zTexCoord = static_cast<float>(z)/static_cast<float>(resampledSize.z) + .5f/static_cast<float>(resampledSize.z);
_shader->setUniform("_zTexCoord", zTexCoord);
if (!isTexture2D) {
float zTexCoord = static_cast<float>(z)/static_cast<float>(resampledSize.z) + .5f/static_cast<float>(resampledSize.z);
shader->setUniform("_zTexCoord", zTexCoord);
}
_fbo->attachTexture(resultTexture, GL_COLOR_ATTACHMENT0, 0, z);
LGL_ERROR;
QuadRdr.renderQuad();
}
_fbo->detachAll();
_fbo->deactivate();
_shader->deactivate();
shader->deactivate();
// put resulting image into DataContainer
ImageData* id = new ImageData(3, resampledSize, 1);
ImageData* id = new ImageData(img->getParent()->getDimensionality(), resampledSize, img->getParent()->getNumChannels());
ImageRepresentationGL::create(id, resultTexture);
const ImageMappingInformation& imi = img->getParent()->getMappingInformation();
id->setMappingInformation(ImageMappingInformation(img->getSize(), imi.getOffset(), imi.getVoxelSize() / p_resampleScale.getValue(), imi.getCustomTransformation()));
......
......@@ -84,7 +84,8 @@ namespace campvis {
virtual void updateResult(DataContainer& dataContainer);
virtual void updateProperties(DataContainer& dataContainer);
cgt::Shader* _shader; ///< Shader for resampling
cgt::Shader* _shader2D; ///< Shader for resampling 2D textures
cgt::Shader* _shader3D; ///< Shader for resampling 3D textures
static const std::string loggerCat_;
};
......
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