Commit ddae0632 authored by schultezub's avatar schultezub

more work on IxpvDemo

git-svn-id: https://camplinux.in.tum.de/svn/campvis/trunk@393 bb408c1c-ae56-11e1-83d9-df6b3e0c105e
parent 46eb03ea
......@@ -26,55 +26,49 @@
* commercial licensing please contact the authors. *
* *
**********************************************************************/
#version 330
in vec3 ex_TexCoord;
out vec4 out_Color;
#include "modules/mod_sampler2d.frag"
#include "tools/texture2d.frag"
#include "tools/background.frag"
uniform SAMPLER2D_TYPE colorTex0_;
uniform SAMPLER2D_TYPE depthTex0_;
uniform TEXTURE_PARAMETERS textureParameters0_;
uniform Texture2D _xRayColor;
uniform Texture2D _xRayDepth;
uniform Texture2D _sliceColor;
uniform Texture2D _sliceDepth;
uniform SAMPLER2D_TYPE colorTex1_;
uniform SAMPLER2D_TYPE depthTex1_;
uniform TEXTURE_PARAMETERS textureParameters1_;
uniform SAMPLER2D_TYPE colorTexDRRMax_;
uniform TEXTURE_PARAMETERS textureParametersDRRMax_;
uniform SAMPLER2D_TYPE colorTexDRRClipped_;
uniform TEXTURE_PARAMETERS textureParametersDRRClipped_;
uniform Texture2D _drrFullColor;
uniform Texture2D _drrClippedColor;
/***
* The main method.
***/
void main() {
vec2 fragCoord = gl_FragCoord.xy;
// fetch input textures
vec4 color0 = textureLookup2Dscreen(colorTex0_, textureParameters0_, fragCoord);
float depth0 = textureLookup2Dscreen(depthTex0_, textureParameters0_, fragCoord).z;
vec4 color1 = textureLookup2Dscreen(colorTex1_, textureParameters1_, fragCoord);
float depth1 = textureLookup2Dscreen(depthTex1_, textureParameters1_, fragCoord).z;
vec4 xRayColor = getElement2DNormalized(_xRayColor, ex_TexCoord.xy);
float xRayDepth = getElement2DNormalized(_xRayDepth, ex_TexCoord.xy).z;
vec4 sliceColor = getElement2DNormalized(_sliceColor, ex_TexCoord.xy);
float sliceDepth = getElement2DNormalized(_sliceDepth, ex_TexCoord.xy).z;
float drrMax = textureLookup2Dscreen(colorTexDRRMax_, textureParametersDRRMax_, fragCoord).r;
float drrClipped = textureLookup2Dscreen(colorTexDRRClipped_, textureParametersDRRClipped_, fragCoord).r;
float drrFull = getElement2DNormalized(_drrFullColor, ex_TexCoord.xy).r;
float drrClipped = getElement2DNormalized(_drrClippedColor, ex_TexCoord.xy).r;
float weightingFactor = 0.0;
if (drrClipped > 0)
weightingFactor = clamp(drrClipped / drrMax, 0.0, 1.0);
weightingFactor = clamp(drrClipped / drrFull, 0.0, 1.0);
vec4 fragColor = vec4(0.0, 0.0, 0.0, 1.0);
float fragDepth = weightingFactor;
if (weightingFactor == 0.0)
fragDepth = depth1;
fragDepth = sliceDepth;
else if (weightingFactor == 1.0)
fragDepth = depth0;
fragDepth = xRayDepth;
else
fragDepth = min(depth0, depth1);
fragDepth = min(xRayDepth, sliceDepth);
fragColor = weightingFactor*color0 + (1.0-weightingFactor)*color1;
FragData0 = fragColor;
gl_FragDepth = fragDepth;
out_Color = weightingFactor*xRayColor + (1.0-weightingFactor)*sliceColor;
//gl_FragDepth = fragDepth;
}
......@@ -74,6 +74,20 @@ void main() {
out_Color = vec4(vec3(1.0) - abs(firstColor - secondColor).xyz, max(firstColor.w, secondColor.w));
gl_FragDepth = min(firstDepth, secondDepth);
}
else if (_compositingMethod == 4) {
// depth test
float firstDepth = getElement2DNormalized(_firstDepth, ex_TexCoord.xy).z;
float secondDepth = getElement2DNormalized(_secondDepth, ex_TexCoord.xy).z;
if (firstDepth > secondDepth) {
out_Color = getElement2DNormalized(_secondColor, ex_TexCoord.xy);
gl_FragDepth = secondDepth;
}
else {
out_Color = getElement2DNormalized(_firstColor, ex_TexCoord.xy);
gl_FragDepth = firstDepth;
}
}
else {
// should not occur, but makes the GLSL compiler happy
out_Color = vec4(0.0);
......
......@@ -32,13 +32,17 @@
in vec3 ex_TexCoord;
out vec4 out_Color;
#include "tools/texture2d.frag"
#include "tools/texture3d.frag"
#include "tools/transferfunction.frag"
uniform Texture2D _texture;
uniform Texture3D _texture;
uniform TransferFunction1D _transferFunction;
void main() {
float intensity = getElement2DNormalized(_texture, ex_TexCoord.xy).a;
float intensity = getElement3DNormalized(_texture, ex_TexCoord).a;
out_Color = lookupTF(_transferFunction, intensity);
// don't write fragment if fully transparent (in particular don't write to depth buffer!)
if (out_Color == 0.0)
discard;
}
......@@ -44,27 +44,33 @@ namespace campvis {
, _ctProxy()
, _ctFullEEP(_effectiveRenderTargetSize)
, _ctClippedEEP(_effectiveRenderTargetSize)
, _ctDVR(_effectiveRenderTargetSize)
, _ctFullDRR(_effectiveRenderTargetSize)
, _ctClippedDRR(_effectiveRenderTargetSize)
, _usReader()
, _usSliceRenderer(_effectiveRenderTargetSize)
, _compositor(_effectiveRenderTargetSize)
, _compositor2(_effectiveRenderTargetSize)
, _ixpvCompositor(_effectiveRenderTargetSize)
, _camera("camera", "Camera")
, _trackballHandler(0)
{
addProcessor(&_xrayReader);
addProcessor(&_ctReader);
addProcessor(&_ctProxy);
addProcessor(&_ctFullEEP);
addProcessor(&_ctClippedEEP);
addProcessor(&_ctFullDRR);
addProcessor(&_ctClippedDRR);
addProcessor(&_xrayReader);
addProcessor(&_usReader);
addProcessor(&_usSliceRenderer);
addProcessor(&_ctReader);
addProcessor(&_ctProxy);
addProcessor(&_ctFullEEP);
addProcessor(&_ctClippedEEP);
addProcessor(&_ctDVR);
addProcessor(&_ctFullDRR);
addProcessor(&_ctClippedDRR);
addProcessor(&_compositor);
addProcessor(&_compositor2);
addProcessor(&_ixpvCompositor);
addProperty(&_camera);
......@@ -83,6 +89,7 @@ namespace campvis {
// = Camera Setup =================================================================================
_camera.addSharedProperty(&_ctFullEEP.p_camera);
_camera.addSharedProperty(&_ctClippedEEP.p_camera);
_camera.addSharedProperty(&_ctDVR.p_camera);
_camera.addSharedProperty(&_ctFullDRR.p_camera);
_camera.addSharedProperty(&_ctClippedDRR.p_camera);
_camera.addSharedProperty(&_usSliceRenderer.p_camera);
......@@ -98,6 +105,7 @@ namespace campvis {
_ctReader.p_targetImageID.connect(&_ctProxy.p_sourceImageID);
_ctReader.p_targetImageID.connect(&_ctFullEEP.p_sourceImageID);
_ctReader.p_targetImageID.connect(&_ctClippedEEP.p_sourceImageID);
_ctReader.p_targetImageID.connect(&_ctDVR.p_sourceImageID);
_ctReader.p_targetImageID.connect(&_ctFullDRR.p_sourceImageID);
_ctReader.p_targetImageID.connect(&_ctClippedDRR.p_sourceImageID);
......@@ -107,8 +115,22 @@ namespace campvis {
_ctFullEEP.p_entryImageID.setValue("ct.entry.full");
_ctFullEEP.p_entryImageID.connect(&_ctFullDRR.p_entryImageID);
_ctFullEEP.p_entryImageID.connect(&_ctDVR.p_entryImageID);
_ctFullEEP.p_exitImageID.setValue("ct.exit.full");
_ctFullEEP.p_exitImageID.connect(&_ctFullDRR.p_exitImageID);
_ctFullEEP.p_exitImageID.connect(&_ctDVR.p_exitImageID);
_ctClippedEEP.p_entryImageID.setValue("ct.entry.clipped");
_ctClippedEEP.p_entryImageID.connect(&_ctClippedDRR.p_entryImageID);
_ctClippedEEP.p_exitImageID.setValue("ct.exit.clipped");
_ctClippedEEP.p_exitImageID.connect(&_ctClippedDRR.p_exitImageID);
Geometry1DTransferFunction* tfDvr = new Geometry1DTransferFunction(128, tgt::vec2(0.f, .08f));
// tf->addGeometry(TFGeometry1D::createQuad(tgt::vec2(.5f, 1.f), tgt::col4(0, 0, 0, 0), tgt::col4(0, 0, 0, 180)));
tfDvr->addGeometry(TFGeometry1D::createQuad(tgt::vec2(.4f, .6f), tgt::col4(255, 192, 0, 255), tgt::col4(255, 192, 0, 255)));
_ctDVR.p_transferFunction.replaceTF(tfDvr);
_ctDVR.p_targetImageID.setValue("ct.dvr");
_ctDVR.p_samplingRate.setValue(1.f);
Geometry1DTransferFunction* tf = new Geometry1DTransferFunction(128, tgt::vec2(0.f, .08f));
tf->addGeometry(TFGeometry1D::createQuad(tgt::vec2(.5f, 1.f), tgt::col4(0, 0, 0, 0), tgt::col4(0, 0, 0, 180)));
......@@ -128,8 +150,11 @@ namespace campvis {
_usReader.p_url.setValue("D:\\Medical Data\\XrayDepthPerception\\DataCowLeg\\Ultrasound\\gaussianSmoothedUS_UChar.mhd");
_usReader.p_targetImageID.setValue("us.image");
_usReader.p_targetImageID.connect(&_usSliceRenderer.p_sourceImageID);
_usReader.p_imageOffset.setValue(tgt::vec3(-600.f, 80.f, -530.f));
_usReader.p_voxelSize.setValue(tgt::vec3(1.f, 1.f, 1.3f));
_usSliceRenderer.p_targetImageID.setValue("us.slice");
_usSliceRenderer.p_targetImageID.connect(&_ctClippedEEP.p_geometryImageId);
_usSliceRenderer.p_sliceNumber.setValue(0);
......@@ -141,7 +166,18 @@ namespace campvis {
_compositor.p_targetImageId.setValue("composed");
_compositor.p_compositingMethod.selectById("diff");
_renderTargetID.setValue("us.slice");
_ctDVR.p_targetImageID.connect(&_compositor2.p_firstImageId);
_usSliceRenderer.p_targetImageID.connect(&_compositor2.p_secondImageId);
_compositor2.p_targetImageId.setValue("composed2");
_compositor2.p_compositingMethod.selectById("depth");
_xrayReader.p_targetImageID.connect(&_ixpvCompositor.p_xRayImageId);
_usSliceRenderer.p_targetImageID.connect(&_ixpvCompositor.p_3dSliceImageId);
_ctFullDRR.p_targetImageID.connect(&_ixpvCompositor.p_drrFullImageId);
_ctClippedDRR.p_targetImageID.connect(&_ixpvCompositor.p_drrClippedImageId);
_ixpvCompositor.p_targetImageId.setValue("ixpv");
_renderTargetID.setValue("ixpv");
_trackballHandler->setViewportSize(_renderTargetSize);
}
......@@ -162,6 +198,8 @@ namespace campvis {
if (local != 0) {
DataHandle dh = _data.addData("ct.image.local", local);
Interval<float> ii = local->getNormalizedIntensityRange();
_ctDVR.p_transferFunction.getTF()->setImageHandle(dh);
_ctDVR.p_transferFunction.getTF()->setIntensityDomain(tgt::vec2(ii.getLeft(), ii.getRight()));
_ctFullDRR.p_transferFunction.getTF()->setImageHandle(dh);
_ctFullDRR.p_transferFunction.getTF()->setIntensityDomain(tgt::vec2(ii.getLeft(), ii.getRight()));
_ctClippedDRR.p_transferFunction.getTF()->setImageHandle(dh);
......@@ -198,6 +236,7 @@ namespace campvis {
Interval<float> ii = local->getNormalizedIntensityRange();
_usSliceRenderer.p_transferFunction.getTF()->setImageHandle(dh);
_usSliceRenderer.p_transferFunction.getTF()->setIntensityDomain(tgt::vec2(ii.getLeft(), ii.getRight()));
_usSliceRenderer.updateProperties(img);
_usSliceRenderer.p_sliceNumber.setValue(125);
{
......@@ -231,4 +270,4 @@ namespace campvis {
float ratio = static_cast<float>(_effectiveRenderTargetSize.getValue().x) / static_cast<float>(_effectiveRenderTargetSize.getValue().y);
_camera.setWindowRatio(ratio);
}
}
\ No newline at end of file
}
......@@ -46,6 +46,7 @@
#include "modules/vis/processors/simpleraycaster.h"
#include "modules/vis/processors/rendertargetcompositor.h"
#include "modules/vis/processors/slicerenderer3d.h"
#include "modules/vis/processors/ixpvcompositor.h"
namespace campvis {
......@@ -82,6 +83,7 @@ namespace campvis {
ProxyGeometryGenerator _ctProxy;
EEPGenerator _ctFullEEP;
EEPGenerator _ctClippedEEP;
SimpleRaycaster _ctDVR;
DRRRaycaster _ctFullDRR;
DRRRaycaster _ctClippedDRR;
......@@ -89,6 +91,8 @@ namespace campvis {
SliceRenderer3D _usSliceRenderer;
RenderTargetCompositor _compositor;
RenderTargetCompositor _compositor2;
IxpvCompositor _ixpvCompositor;
CameraProperty _camera;
......
......@@ -43,11 +43,12 @@
namespace campvis {
static const GenericOption<CompositingMode> compositingOptions[4] = {
static const GenericOption<CompositingMode> compositingOptions[5] = {
GenericOption<CompositingMode>("first", "Only First", CompositingModeFirst),
GenericOption<CompositingMode>("second", "Only Second", CompositingModeSecond),
GenericOption<CompositingMode>("alpha", "Alpha Blending", CompositingModeAlpha),
GenericOption<CompositingMode>("diff", "Difference", CompositingModeDifference)
GenericOption<CompositingMode>("diff", "Difference", CompositingModeDifference),
GenericOption<CompositingMode>("depth", "Depth Test", CompositingModeDepth)
};
const std::string RenderTargetCompositor::loggerCat_ = "CAMPVis.modules.vis.RenderTargetCompositor";
......@@ -57,7 +58,7 @@ namespace campvis {
, p_firstImageId("FirstImageId", "First Input Image", "", DataNameProperty::READ)
, p_secondImageId("SecondImageId", "Second Input Image", "", DataNameProperty::READ)
, p_targetImageId("TargetImageId", "Output Image", "", DataNameProperty::WRITE)
, p_compositingMethod("CompositingMethod", "Compositing Method", compositingOptions, 4)
, p_compositingMethod("CompositingMethod", "Compositing Method", compositingOptions, 5)
, p_alphaValue("AlphaValue", "AlphaValue", .5f, 0.f, 1.f)
, _shader(0)
{
......
......@@ -51,6 +51,7 @@ namespace campvis {
CompositingModeSecond = 1,
CompositingModeAlpha = 2,
CompositingModeDifference = 3,
CompositingModeDepth = 4
};
}
......
......@@ -58,6 +58,7 @@ namespace campvis {
{
addProperty(&p_sourceImageID);
addProperty(&p_targetImageID);
addProperty(&p_camera);
addProperty(&p_sliceNumber);
addProperty(&p_transferFunction);
}
......@@ -100,6 +101,8 @@ namespace campvis {
ImageDataRenderTarget* rt = new ImageDataRenderTarget(tgt::svec3(_renderTargetSize.getValue(), 1));
glPushAttrib(GL_ALL_ATTRIB_BITS);
glEnable(GL_DEPTH_TEST);
_shader->activate();
_shader->setIgnoreUniformLocationError(true);
......@@ -107,6 +110,9 @@ namespace campvis {
_shader->setUniform("_projectionMatrix", cam.getProjectionMatrix());
_shader->setUniform("_viewMatrix", cam.getViewMatrix());
tgt::mat4 trafoMatrix = tgt::mat4::createScale(tgt::vec3(-1.f, 1.f, -1.f));
_shader->setUniform("_modelMatrix", trafoMatrix);
tgt::TextureUnit inputUnit, tfUnit;
img->bind(_shader, inputUnit);
p_transferFunction.getTF()->bind(_shader, tfUnit);
......@@ -120,6 +126,7 @@ namespace campvis {
_shader->deactivate();
tgt::TextureUnit::setZeroUnit();
glPopAttrib();
data.addData(p_targetImageID.getValue(), rt);
p_targetImageID.issueWrite();
......
......@@ -82,10 +82,10 @@ namespace campvis {
IntProperty p_sliceNumber; ///< number of the slice to extract
TransferFunctionProperty p_transferFunction; ///< Transfer function
protected:
/// adapts the range of the p_sliceNumber property to the image
void updateProperties(const ImageData* img);
protected:
tgt::Shader* _shader; ///< Shader for slice rendering
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