Commit 47ec05ba authored by schultezub's avatar schultezub

added masking to EEPGenerator

git-svn-id: https://camplinux.in.tum.de/svn/campvis/trunk@284 bb408c1c-ae56-11e1-83d9-df6b3e0c105e
parent 09e28d4b
......@@ -49,6 +49,9 @@ namespace TUMVis {
, _exitImageID("exitImageID", "Output Exit Points Image", "eep.exit", DataNameProperty::WRITE)
, _camera("camera", "Camera")
, _enableMirror("enableMirror", "Enable Virtual Mirror Feature", false)
, _applyMask("applyMask", "Apply Mask to image", false, InvalidationLevel::INVALID_SHADER)
, _maskID("maskID", "Mask Image ID", "mask", DataNameProperty::READ)
, _maskColor("maskColor", "Mask Color", tgt::vec4(0.f), tgt::vec4(0.f), tgt::vec4(1.f))
, _shader(0)
{
addProperty(&_sourceImageID);
......@@ -58,6 +61,9 @@ namespace TUMVis {
addProperty(&_exitImageID);
addProperty(&_camera);
addProperty(&_enableMirror);
addProperty(&_applyMask);
addProperty(&_maskID);
addProperty(&_maskColor);
}
EEPGenerator::~EEPGenerator() {
......@@ -85,6 +91,11 @@ namespace TUMVis {
if (img != 0 && proxyGeometry != 0 && _shader != 0) {
if (img->getDimensionality() == 3) {
if (_invalidationLevel.isInvalidShader()) {
_shader->setHeaders(generateHeader());
_shader->rebuild();
}
tgt::Bounds volumeExtent = img->getWorldBounds();
tgt::Bounds textureBounds(tgt::vec3(0.f), tgt::vec3(1.f));
......@@ -124,6 +135,17 @@ namespace TUMVis {
_shader->setUniform("_modelMatrix", mirrorMatrix);
_shader->setUniform("_projectionMatrix", _camera.getValue().getProjectionMatrix());
_shader->setUniform("_viewMatrix", _camera.getValue().getViewMatrix());
tgt::TextureUnit maskUnit;
if (_applyMask.getValue()) {
_shader->setUniform("_viewportSizeRCP", 1.f / tgt::vec2(_renderTargetSize.getValue()));
_shader->setUniform("_maskColor", _maskColor.getValue());
DataContainer::ScopedTypedData<ImageDataRenderTarget> mask(data, _maskID.getValue());
if (mask != 0) {
mask->bind(_shader, &maskUnit, 0, "_maskImage");
}
}
glEnable(GL_CULL_FACE);
// create entry points texture
......@@ -168,4 +190,13 @@ namespace TUMVis {
_invalidationLevel.setValid();
}
std::string EEPGenerator::generateHeader() const {
std::string toReturn;
if (_applyMask.getValue())
toReturn += "#define APPLY_MASK 1\n";
return toReturn;
}
}
......@@ -28,9 +28,28 @@
#version 330
in vec3 ex_TexCoord; ///< incoming texture coordinate
out vec4 out_Color; ///< outgoing fragment color
in vec3 ex_TexCoord; ///< incoming texture coordinate
out vec4 out_Color; ///< outgoing fragment color
#ifdef APPLY_MASK
#include "tools/texture2d.frag"
uniform vec2 _viewportSizeRCP;
uniform Texture2D _maskImage; ///< mask image
uniform vec4 _maskColor; ///< mask color
#endif
void main() {
#ifdef APPLY_MASK
vec2 fragCoord = gl_FragCoord.xy * _viewportSizeRCP;
vec4 maskValue = getElement2DNormalized(_maskImage, fragCoord);
if (distance(maskValue, _maskColor) > 0.01) {
out_Color = vec4(ex_TexCoord, 1.0);
}
else {
discard;
}
#else
out_Color = vec4(ex_TexCoord, 1.0);
#endif
}
......@@ -74,7 +74,7 @@ namespace TUMVis {
DataNameProperty _sourceImageID; ///< image ID for input image
DataNameProperty _geometryID; ///< ID for input geometry
DataNameProperty _mirrorID; ///< ID for input mirror geometry
DataNameProperty _mirrorID; ///< ID for input mirror geometry
DataNameProperty _entryImageID; ///< image ID for output entry points image
DataNameProperty _exitImageID; ///< image ID for output exit points image
......@@ -82,8 +82,18 @@ namespace TUMVis {
BoolProperty _enableMirror; ///< Enable Virtual Mirror Feature
BoolProperty _applyMask; ///< Flag whether to apply mask
DataNameProperty _maskID; ///< ID for mask image (optional)
Vec4Property _maskColor; ///< Mask color
protected:
/**
* \see RaycastingProcessor::generateHeader()
* \return "#define APPLY_MASK 1" if \a _applyMask is set to true.
*/
virtual std::string generateHeader() const;
tgt::Shader* _shader; ///< Shader for EEP generation
static const std::string loggerCat_;
......
......@@ -45,11 +45,13 @@ namespace TUMVis {
, _geometryID("geometryID", "Input Geometry ID", "gr.input", DataNameProperty::READ)
, _renderTargetID("_renderTargetID", "Output Image", "gr.output", DataNameProperty::WRITE)
, _camera("camera", "Camera")
, _color("color", "Rendering Color", tgt::vec4(1.f), tgt::vec4(0.f), tgt::vec4(1.f))
, _shader(0)
{
addProperty(&_geometryID);
addProperty(&_renderTargetID);
addProperty(&_camera);
addProperty(&_color);
}
GeometryRenderer::~GeometryRenderer() {
......@@ -80,7 +82,7 @@ namespace TUMVis {
_shader->activate();
_shader->setUniform("_projectionMatrix", _camera.getValue().getProjectionMatrix());
_shader->setUniform("_viewMatrix", _camera.getValue().getViewMatrix());
_shader->setUniform("_color", tgt::vec4(1.f));
_shader->setUniform("_color", _color.getValue());
// create entry points texture
ImageDataRenderTarget* rt = new ImageDataRenderTarget(tgt::svec3(_renderTargetSize.getValue(), 1), GL_RGBA16);
......
......@@ -74,6 +74,8 @@ namespace TUMVis {
DataNameProperty _renderTargetID; ///< image ID for output image
CameraProperty _camera;
Vec4Property _color; ///< rendering color
protected:
tgt::Shader* _shader; ///< Shader for EEP generation
......
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