Commit 0806d758 authored by Christian Schulte zu Berge's avatar Christian Schulte zu Berge
Browse files

Various small fixes/improvements to prepare for evaluation.

parent f03b6e88
......@@ -47,9 +47,7 @@ namespace cgt {
}
BufferObject::~BufferObject() {
if (_id != 0) {
GLGC.addGarbageBufferObject(_id);
}
glDeleteBuffers(1, &_id);
}
void BufferObject::bind() {
......
......@@ -61,6 +61,8 @@ uniform float _confidenceScaling;
uniform float _hue;
uniform float _blurredScale;
uniform float _mixFactor = 0.5;
void main() {
#ifdef USE_3D_TEX
vec3 texCoord = vec3(ex_TexCoord.xy, _usTextureParams._sizeRCP.z * (_sliceNumber + 0.5));
......@@ -118,20 +120,24 @@ void main() {
hcy.y = uncertainty;
out_Color.xyz = hcy2rgb(hcy);
break;
case 8:
case 8: // LAB
{
out_Color = lookupTF(_transferFunction, _transferFunctionParams, texel.r);
vec3 lch = rgb2lch(out_Color.xyz);
lch.z = 6.2831853 * _hue;
lch.y = 100.0 * (uncertainty);
out_Color.xyz = lch2rgb(lch);
break;
}
case 9:
{
out_Color = lookupTF(_transferFunction, _transferFunctionParams, texel.r);
vec3 hlch = lab2lch(xyz2hlab(rgb2xyz(out_Color.xyz)));
//hlch.z = 6.2831853 * _hue;
//hlch.y = 100.0 * (uncertainty);
out_Color.xyz = xyz2rgb(hlab2xyz(lch2lab(hlch)));
break;
}
case 10:
float intensity = clamp(mix((2.0 * texel.r - blurred.r), blurred.r, uncertainty), 0.0f, 1.0f);
out_Color = lookupTF(_transferFunction, _transferFunctionParams, intensity);
......@@ -147,5 +153,22 @@ void main() {
vec3 color = hsv2rgb(vec3(_hue, uncertainty, 0.8));
out_Color.xyz = (uncertainty) * color + (1-uncertainty)*out_Color.xyz;
break;
case 13: // hybrid
{
float mixFactor = _mixFactor;
if (mixFactor < 0.1)
mixFactor = 0.0;
float blurredIntensity = 1.0 - clamp(mix((2.0 * texel.r - blurred.r), blurred.r, uncertainty), 0.0, 1.0);
vec4 theColor = vec4(blurredIntensity);
vec3 lch = rgb2lch(theColor.xyz);
lch.z = 6.2831853 * _hue;
lch.y = 100.0 * (uncertainty);
theColor.xyz = lch2rgb(lch);
out_Color = mix(vec4(blurredIntensity), theColor, mixFactor);
break;
}
}
}
......@@ -41,7 +41,7 @@
namespace campvis {
const std::string AdvancedUsFusion::loggerCat_ = "CAMPVis.modules.vis.AdvancedUsFusion";
GenericOption<std::string> viewOptions[13] = {
GenericOption<std::string> viewOptions[14] = {
GenericOption<std::string>("us", "Ultrasound Only"),
GenericOption<std::string>("smoothed", "Smoothed US Only"),
GenericOption<std::string>("cm", "Confidence Map US Only"),
......@@ -54,7 +54,8 @@ namespace campvis {
GenericOption<std::string>("mappingHunterLAB", "Mapping Uncertainty Hunter L*a*b*"),
GenericOption<std::string>("mappingSharpness", "Mapping Uncertainty to Sharpness"),
GenericOption<std::string>("pixelate", "Pixelate (Experimental)"),
GenericOption<std::string>("colorOverlay", "Color Overlay")
GenericOption<std::string>("colorOverlay", "Color Overlay"),
GenericOption<std::string>("mappingHybrid", "Hybrid Mapping to Chroma and Sharpness")
};
AdvancedUsFusion::AdvancedUsFusion(IVec2Property* viewportSizeProp)
......@@ -68,10 +69,11 @@ namespace campvis {
, p_sliceNumber("sliceNumber", "Slice Number", 0, 0, 0)
, p_transferFunction("transferFunction", "Transfer Function", new SimpleTransferFunction(256))
, p_confidenceTF("ConfidenceTF", "Confidence to Uncertainty TF", new Geometry1DTransferFunction(256))
, p_view("View", "Image to Render", viewOptions, 13)
, p_view("View", "Image to Render", viewOptions, 14)
, p_blurredScaling("BlurredScaling", "Blurred Scaling", 1.f, .001f, 1000.f, 0.1f)
, p_confidenceScaling("ConfidenceScaling", "Confidence Scaling", 1.f, .001f, 1000.f, 0.1f)
, p_hue("Hue", "Hue for Uncertainty Mapping", .15f, 0.f, 1.f)
, p_mixFactor("MixFactor", "Mix Factor", .5f, 0.f, 1.f, .1f, 1)
, p_use3DTexture("Use3DTexture", "Use 3D Texture", false)
, _shader(0)
{
......@@ -88,6 +90,8 @@ namespace campvis {
addProperty(p_view);
addProperty(p_confidenceScaling);
addProperty(p_hue);
addProperty(p_mixFactor);
p_mixFactor.setVisible(false);
Geometry1DTransferFunction* tf = static_cast<Geometry1DTransferFunction*>(p_confidenceTF.getTF());
tf->addGeometry(TFGeometry1D::createQuad(cgt::vec2(0.f, 1.f), cgt::col4(0, 0, 0, 96), cgt::col4(0, 0, 0, 0)));
......@@ -126,6 +130,7 @@ namespace campvis {
_shader->setUniform("_confidenceScaling", p_confidenceScaling.getValue());
_shader->setUniform("_hue", p_hue.getValue());
_shader->setUniform("_blurredScale", 1.f / p_blurredScaling.getValue());
_shader->setUniform("_mixFactor", p_mixFactor.getValue());
cgt::TextureUnit usUnit, blurredUnit, confidenceUnit, tfUnit, tf2Unit;
img->bind(_shader, usUnit, "_usImage", "_usTextureParams");
......@@ -192,6 +197,8 @@ namespace campvis {
}
p_use3DTexture.setValue(img->getDimensionality() == 3);
}
p_mixFactor.setVisible(p_view.getOptionId() == "mappingHybrid");
}
std::string AdvancedUsFusion::generateHeader() const {
......
......@@ -89,6 +89,7 @@ namespace campvis {
FloatProperty p_blurredScaling;
FloatProperty p_confidenceScaling;
FloatProperty p_hue;
FloatProperty p_mixFactor;
BoolProperty p_use3DTexture;
protected:
......
......@@ -48,6 +48,7 @@ namespace campvis {
: AutoEvaluationPipeline(dc)
, _usIgtlReader()
, _usCropFilter(&_canvasSize)
, _usPreBlur(&_canvasSize)
, _usBlurFilter(&_canvasSize)
, _usResampler(&_canvasSize)
, _usMapsSolver()
......@@ -59,6 +60,7 @@ namespace campvis {
, p_connectDisconnectButton("ConnectToIGTLink", "Connect/Disconnect")
, p_resamplingScale("ResampleScale", "Resample Scale", 0.5f, 0.01f, 1.0f)
, p_beta("Beta", "Beta", 80.0f, 1.0f, 200.0f)
, p_resetToDefault("ResetToDefault", "Reset Settings to Default")
, p_collectStatistics("CollectStatistics", "Collect Statistics", false)
, p_copyStatisticsToClipboard("CopyStatisticsToClipboard", "Copy Statistics To Clipboard as CSV")
, p_showAdvancedOptions("ShowAdvancedOptions", "Advanced options...", false)
......@@ -66,7 +68,7 @@ namespace campvis {
, p_gaussianFilterSize("GaussianSigma", "Blur amount", 2.5f, 1.0f, 10.0f)
, p_gradientScaling("GradientScaling", "Scaling factor for gradients", 2.0f, 0.001, 10)
, p_alpha("Alpha", "Alpha", 2.0f, 0.0f, 10.0f)
, p_gamma("Gamma", "Gamma", 0.03f, 0.0f, 0.4f, 0.001, 4)
, p_gamma("Gamma", "Gamma", 0.05f, 0.0f, 0.4f, 0.001, 4)
, p_fanHalfAngle("FanHalfAngle", "Fan Half Angle", 28.0f, 1.0f, 90.0f)
, p_fanInnerRadius("FanInnerRadius", "Fan Inner Radius", 0.222f, 0.001f, 0.999f)
, p_useSpacingEncodedFanGeometry("UseSpacingEncodedFanGeomtry", "Use spacing encoded fan geometry", true)
......@@ -80,6 +82,7 @@ namespace campvis {
addProcessor(&_usIgtlReader);
addProcessor(&_usCropFilter);
addProcessor(&_usPreBlur);
addProcessor(&_usBlurFilter);
addProcessor(&_usResampler);
addProcessor(&_usMapsSolver);
......@@ -92,6 +95,7 @@ namespace campvis {
addProperty(p_connectDisconnectButton);
addProperty(p_resamplingScale);
addProperty(p_beta);
addProperty(p_resetToDefault);
addProperty(p_collectStatistics);
addProperty(p_copyStatisticsToClipboard);
......@@ -139,7 +143,11 @@ namespace campvis {
_usIgtlReader.p_targetImagePrefix.setValue("us.igtl.");
_usCropFilter.p_inputImage.setValue("us.igtl.CAMPUS");
_usCropFilter.p_outputImage.setValue("us");
_usCropFilter.p_outputImage.setValue("us.cropped");
_usPreBlur.p_inputImage.setValue("us.cropped");
_usPreBlur.p_outputImage.setValue("us");
_usPreBlur.p_sigma.setValue(.6f);
_usBlurFilter.p_inputImage.setValue("us");
_usBlurFilter.p_outputImage.setValue("us.blurred");
......@@ -168,6 +176,7 @@ namespace campvis {
// Bind buttons to event handlers
p_connectDisconnectButton.s_clicked.connect(this, &CudaConfidenceMapsDemo::toggleIGTLConnection);
p_resetToDefault.s_clicked.connect(this, &CudaConfidenceMapsDemo::resetSettingsToDefault);
p_copyStatisticsToClipboard.s_clicked.connect(this, &CudaConfidenceMapsDemo::copyStatisticsToClipboard);
// Bind pipeline proeprties to processor properties
......@@ -205,7 +214,8 @@ namespace campvis {
_usFusion.invalidate(AbstractProcessor::INVALID_RESULT);
executeProcessorAndCheckOpenGLState(&_usIgtlReader);
executeProcessorAndCheckOpenGLState(&_usCropFilter);
executeProcessorAndCheckOpenGLState(&_usBlurFilter) ;
executeProcessorAndCheckOpenGLState(&_usPreBlur);
executeProcessorAndCheckOpenGLState(&_usBlurFilter);
executeProcessorAndCheckOpenGLState(&_usResampler);
executeProcessorAndCheckOpenGLState(&_usMapsSolver);
......@@ -342,7 +352,7 @@ namespace campvis {
_usFusion.p_view.setValue(8); // LAB
{
Geometry1DTransferFunction* tf = new Geometry1DTransferFunction(256);
tf->addGeometry(TFGeometry1D::createQuad(cgt::vec2(0.0f, 0.5f), cgt::col4(0, 0, 0, 255), cgt::col4(0, 0, 0, 0)));
tf->addGeometry(TFGeometry1D::createQuad(cgt::vec2(0.0f, 0.5f), cgt::col4(0, 0, 0, 192), cgt::col4(0, 0, 0, 0)));
_usFusion.p_confidenceTF.replaceTF(tf);
_usFusion.p_hue.setValue(0.23f);
}
......@@ -397,6 +407,15 @@ namespace campvis {
_usIgtlReader.p_disconnect.click();
}
void CudaConfidenceMapsDemo::resetSettingsToDefault() {
p_resamplingScale.setValue(.5f);
p_gaussianFilterSize.setValue(2.5f);
p_gradientScaling.setValue(2.f);
p_alpha.setValue(2.f);
p_beta.setValue(80.f);
p_gamma.setValue(.05f);
}
void CudaConfidenceMapsDemo::copyStatisticsToClipboard() {
// Copy statistics to the clipboard in CSV format
std::cout << "Have " << _statistics.size() << " stats items" << std::endl;
......
......@@ -32,6 +32,7 @@
#include "core/properties/buttonproperty.h"
#include "modules/modulesapi.h"
#include "modules/pipelinefactory.h"
#include "modules/base/processors/matrixprocessor.h"
#include "modules/preprocessing/processors/glgaussianfilter.h"
#include "modules/preprocessing/processors/glimagecrop.h"
......@@ -77,12 +78,14 @@ namespace campvis {
virtual void onPropertyChanged(const AbstractProperty* prop);
void toggleIGTLConnection();
void resetSettingsToDefault();
void copyStatisticsToClipboard();
void setAdvancedPropertiesVisibility(bool visible);
// Processors
OpenIGTLinkClient _usIgtlReader;
GlImageCrop _usCropFilter;
GlGaussianFilter _usPreBlur;
GlGaussianFilter _usBlurFilter;
GlImageResampler _usResampler;
CudaConfidenceMapsSolver _usMapsSolver;
......@@ -97,6 +100,8 @@ namespace campvis {
FloatProperty p_resamplingScale;
FloatProperty p_beta;
ButtonProperty p_resetToDefault;
BoolProperty p_collectStatistics;
ButtonProperty p_copyStatisticsToClipboard;
......@@ -137,6 +142,7 @@ namespace campvis {
tbb::tick_count _statisticsLastUpdateTime;
};
template class PipelineRegistrar<CudaConfidenceMapsDemo>;
}
#endif // CUDACONFIDENCEMAPSDEMO_H__
......@@ -48,7 +48,7 @@ namespace campvis {
: VisualizationProcessor(viewportSizeProp)
, p_inputImage("InputImage", "Input Image", "", DataNameProperty::READ)
, p_outputImage("OutputImage", "Output Image", "GlGaussianFilter.out", DataNameProperty::WRITE)
, p_sigma("Sigma", "Sigma (relates to kernel size)", 2.5f, 1.f, MAX_SIGMA, .1f, 1)
, p_sigma("Sigma", "Sigma (relates to kernel size)", 2.5f, 0.4f, MAX_SIGMA, .1f, 1)
, _shader2D(0)
, _shader3D(0)
, _kernelBuffer(0)
......@@ -56,7 +56,7 @@ namespace campvis {
{
addProperty(p_inputImage);
addProperty(p_outputImage);
addProperty(p_sigma);
addProperty(p_sigma, INVALID_RESULT | INVALID_PROPERTIES);
}
GlGaussianFilter::~GlGaussianFilter() {
......@@ -80,6 +80,8 @@ namespace campvis {
_kernelBuffer = new cgt::BufferObject(cgt::BufferObject::TEXTURE_BUFFER, cgt::BufferObject::USAGE_STATIC_DRAW);
glGenTextures(1, &_kernelBufferTexture);
invalidate(INVALID_PROPERTIES);
LGL_ERROR;
}
......@@ -110,13 +112,6 @@ namespace campvis {
resultTextures[i] = new cgt::Texture(img->getTexture()->getType(), size, img->getTexture()->getInternalFormat(), cgt::Texture::LINEAR);
}
// create and upload kernel buffer
GLfloat kernel[MAX_HALF_KERNEL_SIZE];
for (int i = 0; i <= halfKernelSize; ++i) {
kernel[i] = exp(- static_cast<GLfloat>(i*i) / (2.f * p_sigma.getValue() * p_sigma.getValue()));
}
_kernelBuffer->data(kernel, (halfKernelSize + 1) * sizeof(GLfloat), cgt::BufferObject::FLOAT, 1);
// we need to distinguish 2D and 3D case
cgt::Shader* leShader = (size.z == 1) ? _shader2D : _shader3D;
......@@ -211,5 +206,17 @@ namespace campvis {
LDEBUG("No suitable input image found.");
}
}
void GlGaussianFilter::updateProperties(DataContainer& data) {
int halfKernelSize = static_cast<int>(2.5 * p_sigma.getValue());
cgtAssert(halfKernelSize < MAX_HALF_KERNEL_SIZE, "halfKernelSize too big -> kernel uniform buffer will be out of bounds!")
// create and upload kernel buffer
GLfloat kernel[MAX_HALF_KERNEL_SIZE];
for (int i = 0; i <= halfKernelSize; ++i) {
kernel[i] = exp(-static_cast<GLfloat>(i*i) / (2.f * p_sigma.getValue() * p_sigma.getValue()));
}
_kernelBuffer->data(kernel, (halfKernelSize + 1) * sizeof(GLfloat), cgt::BufferObject::FLOAT, 1);
}
}
......@@ -83,6 +83,8 @@ namespace campvis {
protected:
/// \see AbstractProcessor::updateResult
virtual void updateResult(DataContainer& dataContainer);
/// \see AbstractProcessor::updateProperties
virtual void updateProperties(DataContainer& dataContainer);
/**
* 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