From f704deb8acf8fba750bb9d325a54b9c8c9929e2e Mon Sep 17 00:00:00 2001 From: schultezub Date: Wed, 13 Feb 2013 17:06:33 +0000 Subject: [PATCH] added mipmap filtering to GL textures further work on AdvancedUsFusion processor introducing pixelate mode git-svn-id: https://camplinux.in.tum.de/svn/campvis/trunk@471 bb408c1c-ae56-11e1-83d9-df6b3e0c105e --- .../classification/simpletransferfunction.cpp | 2 +- core/datastructures/imagerepresentationgl.cpp | 2 +- core/pipeline/visualizationpipeline.cpp | 11 +++++--- core/pipeline/visualizationpipeline.h | 1 + ext/tgt/texture.cpp | 10 +++++-- .../advancedusvis/glsl/advancedusfusion.frag | 26 ++++++++++++------- .../processors/advancedusfusion.cpp | 21 +++++++++------ .../processors/advancedusfusion.h | 3 ++- 8 files changed, 51 insertions(+), 25 deletions(-) diff --git a/core/classification/simpletransferfunction.cpp b/core/classification/simpletransferfunction.cpp index 324454ea..692824d4 100644 --- a/core/classification/simpletransferfunction.cpp +++ b/core/classification/simpletransferfunction.cpp @@ -70,7 +70,7 @@ namespace campvis { tgt::col4 diff = _rightColor - _leftColor; for (size_t i = 0; i < _size.x; ++i) { - float multiplier = static_cast(i) / _size.x; + float multiplier = static_cast(i) / (_size.x - 1); tgt::col4& texel = _texture->texel(i); for (size_t j = 0; j < 4; ++j) { texel[j] = static_cast(_leftColor[j] + (static_cast(diff[j]) * multiplier)); diff --git a/core/datastructures/imagerepresentationgl.cpp b/core/datastructures/imagerepresentationgl.cpp index 64965e26..60644df5 100644 --- a/core/datastructures/imagerepresentationgl.cpp +++ b/core/datastructures/imagerepresentationgl.cpp @@ -117,7 +117,7 @@ namespace campvis { void ImageRepresentationGL::createTexture(const WeaklyTypedPointer& wtp) { tgtAssert(wtp._pointer != 0, "Pointer to image data must not be 0!"); - _texture = new tgt::Texture(reinterpret_cast(wtp._pointer), getSize(), wtp.getGlFormat(), wtp.getGlInternalFormat(), wtp.getGlDataType(), tgt::Texture::LINEAR); + _texture = new tgt::Texture(reinterpret_cast(wtp._pointer), getSize(), wtp.getGlFormat(), wtp.getGlInternalFormat(), wtp.getGlDataType(), tgt::Texture::MIPMAP); setupAndUploadTexture(_texture, wtp.isInteger(), wtp.isSigned()); } diff --git a/core/pipeline/visualizationpipeline.cpp b/core/pipeline/visualizationpipeline.cpp index 7ea8d59a..c547f018 100644 --- a/core/pipeline/visualizationpipeline.cpp +++ b/core/pipeline/visualizationpipeline.cpp @@ -44,6 +44,7 @@ namespace campvis { : AbstractPipeline() , tgt::EventListener() , _lqMode(false) + , _ignoreCanvasSizeUpdate(false) , _canvasSize("CanvasSize", "Canvas Size", tgt::ivec2(128, 128), tgt::ivec2(1, 1), tgt::ivec2(4096, 4096)) , _effectiveRenderTargetSize("EffectiveRenderTargetSize", "Render Target Size", tgt::ivec2(128, 128), tgt::ivec2(1, 1), tgt::ivec2(4096, 4096)) , _renderTargetID("renderTargetID", "Render Target ID", "VisualizationPipeline.renderTarget") @@ -85,8 +86,9 @@ namespace campvis { } void VisualizationPipeline::setRenderTargetSize(const tgt::ivec2& size) { - if (_canvasSize.getValue() != size) + if (_canvasSize.getValue() != size && !_ignoreCanvasSizeUpdate) { _canvasSize.setValue(size); + } updateEffectiveRenderTargetSize(); } @@ -116,9 +118,12 @@ namespace campvis { void VisualizationPipeline::onPropertyChanged(const AbstractProperty* prop) { if (prop == &_renderTargetID) s_renderTargetChanged(); - else if (prop == &_canvasSize && _canvas != 0) { - if (_canvasSize.getValue() != _canvas->getSize()) + else if (prop == &_canvasSize && _canvas != 0 && !_ignoreCanvasSizeUpdate) { + if (_canvasSize.getValue() != _canvas->getSize()) { + _ignoreCanvasSizeUpdate = true; _canvas->setSize(_canvasSize.getValue()); + _ignoreCanvasSizeUpdate = false; + } } else AbstractPipeline::onPropertyChanged(prop); diff --git a/core/pipeline/visualizationpipeline.h b/core/pipeline/visualizationpipeline.h index a5699866..50eee65b 100644 --- a/core/pipeline/visualizationpipeline.h +++ b/core/pipeline/visualizationpipeline.h @@ -180,6 +180,7 @@ namespace campvis { IVec2Property _canvasSize; ///< original canvas size bool _lqMode; ///< Flag whether low quality mode is enables + bool _ignoreCanvasSizeUpdate; IVec2Property _effectiveRenderTargetSize; ///< actual size of the render targets (considering LQ mode) StringProperty _renderTargetID; ///< ID of the render target image to be rendered to the canvas diff --git a/ext/tgt/texture.cpp b/ext/tgt/texture.cpp index af982432..5c2c3b84 100644 --- a/ext/tgt/texture.cpp +++ b/ext/tgt/texture.cpp @@ -292,8 +292,8 @@ void Texture::applyFilter() { glTexParameterf(type_, GL_TEXTURE_MAX_ANISOTROPY_EXT, GpuCaps.getMaxTextureAnisotropy()); case MIPMAP: - glTexParameteri(type_,GL_TEXTURE_MAG_FILTER,GL_LINEAR); - glTexParameteri(type_,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_LINEAR); + glTexParameteri(type_,GL_TEXTURE_MAG_FILTER,GL_NEAREST_MIPMAP_NEAREST); + glTexParameteri(type_,GL_TEXTURE_MIN_FILTER,GL_NEAREST_MIPMAP_NEAREST); glTexParameteri(type_, GL_SGIS_generate_mipmap, GL_TRUE); break; } @@ -326,17 +326,23 @@ void Texture::uploadTexture() { case GL_TEXTURE_1D: glTexImage1D(GL_TEXTURE_1D, 0, internalformat_, dimensions_.x, 0, format_, dataType_, pixels_); + if (filter_ == MIPMAP) + glGenerateMipmap(GL_TEXTURE_1D); break; case GL_TEXTURE_2D: glTexImage2D(GL_TEXTURE_2D, 0, internalformat_, dimensions_.x, dimensions_.y, 0, format_, dataType_, pixels_); + if (filter_ == MIPMAP) + glGenerateMipmap(GL_TEXTURE_2D); break; case GL_TEXTURE_3D: glTexImage3D(GL_TEXTURE_3D, 0, internalformat_, dimensions_.x, dimensions_.y, dimensions_.z, 0, format_, dataType_, pixels_); + if (filter_ == MIPMAP) + glGenerateMipmap(GL_TEXTURE_3D); break; #ifdef GL_TEXTURE_RECTANGLE_ARB diff --git a/modules/advancedusvis/glsl/advancedusfusion.frag b/modules/advancedusvis/glsl/advancedusfusion.frag index d2aa89ec..438cdaa4 100644 --- a/modules/advancedusvis/glsl/advancedusfusion.frag +++ b/modules/advancedusvis/glsl/advancedusfusion.frag @@ -61,7 +61,9 @@ uniform TFParameters1D _transferFunctionParams; uniform int _sliceNumber; uniform int _viewIndex; -uniform float _blurredScaling; +uniform float _confidenceScaling; +uniform float _hue; + void main() { #ifdef USE_3D_TEX @@ -71,8 +73,8 @@ void main() { #endif vec4 texel = TEXTURE_LOOKUP_FUNC(_usImage, _usTextureParams, texCoord); - vec4 blurred = TEXTURE_LOOKUP_FUNC(_blurredImage, _blurredTextureParams, texCoord) * _blurredScaling; - float confidence = TEXTURE_LOOKUP_FUNC(_confidenceMap, _confidenceTextureParams, texCoord).a; + vec4 blurred = TEXTURE_LOOKUP_FUNC(_blurredImage, _blurredTextureParams, texCoord); + float confidence = clamp(TEXTURE_LOOKUP_FUNC(_confidenceMap, _confidenceTextureParams, texCoord).a * _confidenceScaling, 0.0, 1.0); switch (_viewIndex) { case 0: @@ -87,35 +89,35 @@ void main() { case 3: out_Color = lookupTF(_transferFunction, _transferFunctionParams, texel.a); vec3 hsv = rgb2hsv(out_Color.xyz); - hsv.x = 0.15; + hsv.x = _hue; hsv.y = 1.0 - confidence; out_Color.xyz = hsv2rgb(hsv); break; case 4: out_Color = lookupTF(_transferFunction, _transferFunctionParams, texel.a); vec3 hsl = rgb2hsl(out_Color.xyz); - hsl.x = 0.15; + hsl.x = _hue; hsl.y = 1.0 - confidence; out_Color.xyz = hsl2rgb(hsl); break; case 5: out_Color = lookupTF(_transferFunction, _transferFunctionParams, texel.a); vec3 tsl = rgb2tsl(out_Color.xyz); - //tsl.x = 0.15; + //tsl.x = _hue; //tsl.y = 1.0 - confidence; out_Color.xyz = tsl2rgb(tsl); break; case 6: out_Color = lookupTF(_transferFunction, _transferFunctionParams, texel.a); vec3 hcl = rgb2hcl(out_Color.xyz); - hcl.x = 0.15; + hcl.x = _hue; hcl.y = 1.0 - confidence; out_Color.xyz = hcl2rgb(hcl); break; case 7: out_Color = lookupTF(_transferFunction, _transferFunctionParams, texel.a); vec3 hcy = rgb2hcy(out_Color.xyz); - hcy.x = 0.15; + hcy.x = _hue; hcy.y = 1.0 - confidence; out_Color.xyz = hcy2rgb(hcy); break; @@ -127,8 +129,14 @@ void main() { out_Color.xyz = lab2rgb(lab); break; case 9: - float intensity = mix(blurred.a, 2.0 * texel.a - blurred.a, confidence); + float intensity = mix(blurred.a, (2.0 * texel.a - blurred.a), confidence); out_Color = lookupTF(_transferFunction, _transferFunctionParams, intensity); break; + case 10: + float lod = max(floor((1.0 - confidence) * 8.0), 0.0); + + vec4 lodTexel = texture(_usImage, texCoord, lod); + out_Color = lookupTF(_transferFunction, _transferFunctionParams, lodTexel.a); + break; } } diff --git a/modules/advancedusvis/processors/advancedusfusion.cpp b/modules/advancedusvis/processors/advancedusfusion.cpp index 0f45e1c4..3cfa3cc1 100644 --- a/modules/advancedusvis/processors/advancedusfusion.cpp +++ b/modules/advancedusvis/processors/advancedusfusion.cpp @@ -44,7 +44,7 @@ namespace campvis { const std::string AdvancedUsFusion::loggerCat_ = "CAMPVis.modules.vis.AdvancedUsFusion"; - GenericOption viewOptions[10] = { + GenericOption viewOptions[11] = { GenericOption("us", "Ultrasound Only"), GenericOption("smoothed", "Smoothed US Only"), GenericOption("sharpened", "Sharpened US Only"), @@ -54,7 +54,8 @@ namespace campvis { GenericOption("mappingChromacityHCL", "Mapping Uncertainty to Chromacity (HCL)"), GenericOption("mappingChromacityHCY", "Mapping Uncertainty to Chromacity (HCY)"), GenericOption("mappingLAB", "Mapping Uncertainty L*a*b"), - GenericOption("mappingSharpness", "Mapping Uncertainty to Sharpness") + GenericOption("mappingSharpness", "Mapping Uncertainty to Sharpness"), + GenericOption("pixelate", "Pixelate (Experimental)") }; AdvancedUsFusion::AdvancedUsFusion(IVec2Property& canvasSize) @@ -66,8 +67,9 @@ namespace campvis { , p_targetImageID("targetImageID", "Output Image", "", DataNameProperty::WRITE) , p_sliceNumber("sliceNumber", "Slice Number", 0, 0, 0) , p_transferFunction("transferFunction", "Transfer Function", new SimpleTransferFunction(256)) - , p_view("View", "Image to Render", viewOptions, 10) - , p_blurredScaling("BlurredScaling", "Scaling for blurred image intensity", 1.f, .001f, 1000.f) + , p_view("View", "Image to Render", viewOptions, 11) + , p_confidenceScaling("ConfidenceScaling", "Confidence Scaling", 1.f, .001f, 1000.f) + , p_hue("Hue", "Hue for Uncertainty Mapping", .15f, 0.f, 1.f) , p_use3DTexture("Use3DTexture", "Use 3D Texture", false) , _shader(0) { @@ -79,7 +81,8 @@ namespace campvis { addProperty(&p_sliceNumber); addProperty(&p_transferFunction); addProperty(&p_view); - addProperty(&p_blurredScaling); + addProperty(&p_confidenceScaling); + addProperty(&p_hue); decoratePropertyCollection(this); } @@ -119,10 +122,12 @@ namespace campvis { _shader->activate(); decorateRenderProlog(data, _shader); - _shader->setUniform("_sliceNumber", p_sliceNumber.getValue()); + if (p_use3DTexture.getValue()) + _shader->setUniform("_sliceNumber", p_sliceNumber.getValue()); _shader->setUniform("_viewIndex", p_view.getValue()); - _shader->setUniform("_blurredScaling", p_blurredScaling.getValue()); - + _shader->setUniform("_confidenceScaling", p_confidenceScaling.getValue()); + _shader->setUniform("_hue", p_hue.getValue()); + tgt::TextureUnit usUnit, blurredUnit, confidenceUnit, tfUnit; img->bind(_shader, usUnit, "_usImage", "_usTextureParams"); blurred->bind(_shader, blurredUnit, "_blurredImage", "_blurredTextureParams"); diff --git a/modules/advancedusvis/processors/advancedusfusion.h b/modules/advancedusvis/processors/advancedusfusion.h index 915b1618..709e39d2 100644 --- a/modules/advancedusvis/processors/advancedusfusion.h +++ b/modules/advancedusvis/processors/advancedusfusion.h @@ -85,7 +85,8 @@ namespace campvis { IntProperty p_sliceNumber; ///< number of the slice to extract TransferFunctionProperty p_transferFunction; ///< Transfer function GenericOptionProperty p_view; - FloatProperty p_blurredScaling; + FloatProperty p_confidenceScaling; + FloatProperty p_hue; BoolProperty p_use3DTexture; protected: -- GitLab