Commit b854c6c7 authored by schultezub's avatar schultezub
Browse files

fixed AdvancedUsFusion, MhdImageReader and ImageRepresentationITK crashing when handling 2D images

git-svn-id: https://camplinux.in.tum.de/svn/campvis/trunk@468 bb408c1c-ae56-11e1-83d9-df6b3e0c105e
parent 7af1f56b
......@@ -33,17 +33,28 @@ in vec3 ex_TexCoord;
out vec4 out_Color;
#include "tools/colorspace.frag"
#include "tools/texture2d.frag"
#include "tools/texture3d.frag"
#include "tools/transferfunction.frag"
uniform sampler3D _usImage;
uniform TextureParameters3D _usTextureParams;
#ifdef USE_3D_TEX
#define SAMPLER_TYPE sampler3D
#define TEXPARAMS_TYPE TextureParameters3D
#define TEXTURE_LOOKUP_FUNC getElement3DNormalized
#else
#define SAMPLER_TYPE sampler2D
#define TEXPARAMS_TYPE TextureParameters2D
#define TEXTURE_LOOKUP_FUNC getElement2DNormalized
#endif
uniform sampler3D _blurredImage;
uniform TextureParameters3D _blurredTextureParams;
uniform SAMPLER_TYPE _usImage;
uniform TEXPARAMS_TYPE _usTextureParams;
uniform sampler3D _confidenceMap;
uniform TextureParameters3D _confidenceTextureParams;
uniform SAMPLER_TYPE _blurredImage;
uniform TEXPARAMS_TYPE _blurredTextureParams;
uniform SAMPLER_TYPE _confidenceMap;
uniform TEXPARAMS_TYPE _confidenceTextureParams;
uniform sampler1D _transferFunction;
uniform TFParameters1D _transferFunctionParams;
......@@ -53,11 +64,15 @@ uniform int _viewIndex;
uniform float _blurredScaling;
void main() {
#ifdef USE_3D_TEX
vec3 texCoord = vec3(ex_TexCoord.xy, _usTextureParams._sizeRCP.z * (_sliceNumber + 0.5));
#else
vec2 texCoord = ex_TexCoord.xy;
#endif
vec4 texel = getElement3DNormalized(_usImage, _usTextureParams, texCoord);
vec4 blurred = getElement3DNormalized(_blurredImage, _blurredTextureParams, texCoord) * _blurredScaling;
float confidence = getElement3DNormalized(_confidenceMap, _confidenceTextureParams, texCoord).a;
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;
switch (_viewIndex) {
case 0:
......
......@@ -95,7 +95,8 @@ namespace campvis {
_camera.addSharedProperty(&_usEEP.p_camera);
_camera.addSharedProperty(&_usDVR.p_camera);
_usReader.p_url.setValue("D:\\Medical Data\\US Confidence Vis\\01\\BMode_01.mhd");
_usReader.p_url.setValue("D:\\Medical Data\\US Confidence Vis\\CurefabCS\\Stent_Patient_ B-Mode_2013-02-11T14.56.46z\\01_us.mhd");
//_usReader.p_url.setValue("D:\\Medical Data\\US Confidence Vis\\01\\BMode_01.mhd");
//_usReader.p_url.setValue("D:\\Medical Data\\US Confidence Vis\\UltrasoundBoneData\\SynthesEvaluationUnterschenkel\\Athanasios\\US.csvd");
//_usReader.p_url.setValue("D:\\Medical Data\\US Confidence Vis\\transcranial\\us.png");
_usReader.p_targetImageID.setValue("us.image");
......@@ -109,7 +110,8 @@ namespace campvis {
_usReader.p_targetImageID.connect(&_usBlurFilter.p_sourceImageID);
_usReader.p_targetImageID.connect(&_usDenoiseilter.p_sourceImageID);
_confidenceReader.p_url.setValue("D:\\Medical Data\\US Confidence Vis\\01\\Confidence_01.mhd");
_confidenceReader.p_url.setValue("D:\\Medical Data\\US Confidence Vis\\CurefabCS\\Stent_Patient_ B-Mode_2013-02-11T14.56.46z\\01_cm.mhd");
//_confidenceReader.p_url.setValue("D:\\Medical Data\\US Confidence Vis\\01\\Confidence_01.mhd");
//_confidenceReader.p_url.setValue("D:\\Medical Data\\US Confidence Vis\\UltrasoundBoneData\\SynthesEvaluationUnterschenkel\\Athanasios\\Map.csvd");
//_confidenceReader.p_url.setValue("D:\\Medical Data\\US Confidence Vis\\transcranial\\cm.png");
_confidenceReader.p_targetImageID.setValue("confidence.image.read");
......
......@@ -68,6 +68,7 @@ namespace campvis {
, 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_use3DTexture("Use3DTexture", "Use 3D Texture", false)
, _shader(0)
{
addProperty(&p_usImageId);
......@@ -89,7 +90,7 @@ namespace campvis {
void AdvancedUsFusion::init() {
VisualizationProcessor::init();
_shader = ShdrMgr.loadSeparate("core/glsl/passthrough.vert", "modules/advancedusvis/glsl/advancedusfusion.frag", "", false);
_shader = ShdrMgr.loadSeparate("core/glsl/passthrough.vert", "modules/advancedusvis/glsl/advancedusfusion.frag", generateHeader(), false);
_shader->setAttributeLocation(0, "in_Position");
_shader->setAttributeLocation(1, "in_TexCoord");
}
......@@ -110,6 +111,8 @@ namespace campvis {
// source DataHandle has changed
updateProperties(img.getDataHandle());
_sourceImageTimestamp = img.getDataHandle().getTimestamp();
_shader->setHeaders(generateHeader());
_shader->rebuild();
}
std::pair<ImageData*, ImageRepresentationRenderTarget*> rt = ImageRepresentationRenderTarget::createWithImageData(_renderTargetSize.getValue());
......@@ -155,6 +158,14 @@ namespace campvis {
if (p_sliceNumber.getMaxValue() != imgSize.z - 1){
p_sliceNumber.setMaxValue(imgSize.z - 1);
}
p_use3DTexture.setValue(static_cast<const ImageData*>(img.getData())->getDimensionality() == 3);
}
std::string AdvancedUsFusion::generateHeader() const {
std::string toReturn = getDecoratedHeader();
if (p_use3DTexture.getValue())
toReturn += "#define USE_3D_TEX 1\n";
return toReturn;
}
}
......@@ -86,11 +86,14 @@ namespace campvis {
TransferFunctionProperty p_transferFunction; ///< Transfer function
GenericOptionProperty<std::string> p_view;
FloatProperty p_blurredScaling;
BoolProperty p_use3DTexture;
protected:
/// adapts the range of the p_sliceNumber property to the image
void updateProperties(DataHandle img);
std::string generateHeader() const;
tgt::Shader* _shader; ///< Shader for slice rendering
static const std::string loggerCat_;
......
......@@ -134,10 +134,16 @@ namespace campvis {
// TODO: spacing, element size, etc.
if (tfp.hasKey("ElementSpacing")) {
voxelSize = tfp.getVec3("ElementSpacing");
if (dimensionality == 3)
voxelSize = tfp.getVec3("ElementSpacing");
else if (dimensionality == 2)
voxelSize = tgt::vec3(tfp.getVec2("ElementSpacing"), 1.f);
}
if (tfp.hasKey("Position")) {
imageOffset = tfp.getVec3("Position");
if (dimensionality == 3)
imageOffset = tfp.getVec3("Position");
else if (dimensionality == 2)
imageOffset = tgt::vec3(tfp.getVec2("Position"), 0.f);
}
if (tfp.hasKey("ElementNumberOfChannels")) {
numChannels = tfp.getSizeT("ElementNumberOfChannels");
......
......@@ -279,8 +279,10 @@ namespace campvis {
itk::Image<BASETYPE, DIMENSIONALITY>::SizeType size;
size[0] = tester->getSize().x;
size[1] = tester->getSize().y;
size[2] = tester->getSize().z;
if (source->getDimensionality() >= 2)
size[1] = tester->getSize().y;
if (source->getDimensionality() >= 3)
size[2] = tester->getSize().z;
itk::Image<BASETYPE, DIMENSIONALITY>::IndexType start;
start.Fill(0);
......
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