Commit 62ed39ae authored by Declara Denis's avatar Declara Denis Committed by Christian Schulte zu Berge
Browse files

Added Ultrasound Fan Renderer processor.

parent 9c3e05c3
// ================================================================================================
//
// This file is part of the CAMPVis Software Framework.
//
// If not explicitly stated otherwise: Copyright (C) 2012-2014, all rights reserved,
// Christian Schulte zu Berge <christian.szb@in.tum.de>
// Chair for Computer Aided Medical Procedures
// Technische Universitaet Muenchen
// Boltzmannstr. 3, 85748 Garching b. Muenchen, Germany
//
// For a full list of authors and contributors, please refer to the file "AUTHORS.txt".
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
// except in compliance with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software distributed under the
// License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
// either express or implied. See the License for the specific language governing permissions
// and limitations under the License.
//
// ================================================================================================
#include "tools/texture2d.frag"
uniform sampler2D _texture;
uniform TextureParameters2D _textureParams;
uniform bool isMonochromatic = false; // FIXME: Control from processor
in vec3 ex_TexCoord;
out vec4 out_Color;
void main() {
vec4 sample = texture(_texture, vec2(ex_TexCoord.x, 1-ex_TexCoord.y));
if (isMonochromatic) {
out_Color = vec4(sample.rrr, 1);
} else {
out_Color = sample;
}
}
// ================================================================================================
//
// This file is part of the CAMPVis Software Framework.
//
// If not explicitly stated otherwise: Copyright (C) 2012-2014, all rights reserved,
// Christian Schulte zu Berge <christian.szb@in.tum.de>
// Chair for Computer Aided Medical Procedures
// Technische Universitaet Muenchen
// Boltzmannstr. 3, 85748 Garching b. Muenchen, Germany
//
// For a full list of authors and contributors, please refer to the file "AUTHORS.txt".
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
// except in compliance with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software distributed under the
// License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
// either express or implied. See the License for the specific language governing permissions
// and limitations under the License.
//
// ================================================================================================
in vec3 in_Position; ///< incoming vertex position
in vec3 in_TexCoord; ///< incoming texture coordinate
out vec3 ex_TexCoord; ///< outgoing texture coordinate
/// Matrix defining projection transformation
uniform mat4 _projectionMatrix = mat4(
1.0, 0.0, 0.0, 0.0,
0.0, 1.0, 0.0, 0.0,
0.0, 0.0, 1.0, 0.0,
0.0, 0.0, 0.0, 1.0);
// Parameters defining fan geometry
uniform float halfAngle;
uniform float innerRadius;
void main() {
float radius = innerRadius + (1 - innerRadius) * in_Position.y;
vec4 pos = vec4(sin(halfAngle * in_Position.x*2) * radius,
cos(halfAngle * in_Position.x*2) * radius,
in_Position.z, 1);
gl_Position = _projectionMatrix * pos;
ex_TexCoord = in_TexCoord;
}
// ================================================================================================
//
// This file is part of the CAMPVis Software Framework.
//
// If not explicitly stated otherwise: Copyright (C) 2012-2014, all rights reserved,
// Christian Schulte zu Berge <christian.szb@in.tum.de>
// Chair for Computer Aided Medical Procedures
// Technische Universitaet Muenchen
// Boltzmannstr. 3, 85748 Garching b. Muenchen, Germany
//
// For a full list of authors and contributors, please refer to the file "AUTHORS.txt".
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
// except in compliance with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software distributed under the
// License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
// either express or implied. See the License for the specific language governing permissions
// and limitations under the License.
//
// ================================================================================================
#include "usfanrenderer.h"
#include "cgt/glmath.h"
#include "cgt/logmanager.h"
#include "cgt/shadermanager.h"
#include "cgt/textureunit.h"
#include "core/datastructures/imagedata.h"
#include "core/datastructures/renderdata.h"
#include "core/datastructures/imagerepresentationgl.h"
#include "core/datastructures/geometrydatafactory.h"
namespace campvis {
const std::string UsFanRenderer::loggerCat_ = "CAMPVis.modules.cudaconfidencemaps.UsFanRenderer";
UsFanRenderer::UsFanRenderer(IVec2Property* viewportSizeProp)
: VisualizationProcessor(viewportSizeProp)
, p_inputImage("InputImageID", "Input Image ID", "us.input", DataNameProperty::READ)
, p_renderTargetID("RenderTargetID", "Render Target ID", "us.output", DataNameProperty::WRITE)
, p_halfAngle("HalfAngle", "Fan Half Angle", 45.0f, 1.0f, 90.0f)
, p_innerRadius("InnerRadius", "Fan Inner Radius", 0.2f, 0.0f, 0.99f)
, _shader(0)
, _grid(0)
{
addProperty(p_inputImage);
addProperty(p_renderTargetID);
addProperty(p_halfAngle);
addProperty(p_innerRadius);
}
UsFanRenderer::~UsFanRenderer() {
}
void UsFanRenderer::init() {
VisualizationProcessor::init();
_shader = ShdrMgr.load("modules/cudaconfidencemaps/glsl/usfanrenderer.vert", "modules/cudaconfidencemaps/glsl/usfanrenderer.frag", "");
// Creates the grid, with the origin at the center of the top edge, with the +y axis representing depth
_grid = GeometryDataFactory::createGrid(cgt::vec3(-0.5f, 1.0f, 0.0f), cgt::vec3(0.5f, 0.0f, 0.0f),
cgt::vec3(0.0f, 1.0f, 0.0f), cgt::vec3(1.0f, 0.0f, 0.0f),
16, 4);
}
void UsFanRenderer::deinit() {
ShdrMgr.dispose(_shader);
_shader = 0;
delete _grid;
_grid = 0;
VisualizationProcessor::deinit();
}
void UsFanRenderer::updateResult(DataContainer& data) {
ImageRepresentationGL::ScopedRepresentation texture(data, p_inputImage.getValue());
if (_shader == 0 || _grid == 0) {
LDEBUG("Shader or Grid are not initialized.");
return;
}
float halfAngle = cgt::deg2rad(p_halfAngle.getValue());
float innerRadius = p_innerRadius.getValue();
// calculate bounding box of the US fan
cgt::vec3 bbCenter = cgt::vec3(0, cos(halfAngle)*innerRadius/2.0f + 0.5, 0.0f);
float bbHeight = 1.0f - cos(halfAngle)*innerRadius;
float bbWidth = sin(halfAngle) * 2.0f;
cgt::vec2 viewportSize = cgt::vec2(getEffectiveViewportSize());
// Flip y axis and add a little border
cgt::mat4 viewportMatrix = cgt::mat4::createScale(cgt::vec3(1, -1, 1) * 0.95f);
// Adjust the size of the fan to the size of the viewport
if (viewportSize.y / bbHeight * bbWidth > viewportSize.x) {
viewportMatrix *= cgt::mat4::createScale(cgt::vec3(1.0f, viewportSize.x / viewportSize.y, 1.0f) * (1.0f / bbWidth * 2.0f));
} else {
viewportMatrix *= cgt::mat4::createScale(cgt::vec3(viewportSize.y / viewportSize.x, 1.0f, 1.0f) * (1.0f / bbHeight * 2.0f));
}
// Move the fan center
viewportMatrix *= cgt::mat4::createTranslation(-bbCenter);
_shader->activate();
cgt::TextureUnit textureUnit;
textureUnit.activate();
if (texture != nullptr)
texture->bind(_shader, textureUnit, "_texture", "_textureParams");
_shader->setUniform("_projectionMatrix", viewportMatrix);
_shader->setUniform("halfAngle", halfAngle);
_shader->setUniform("innerRadius", innerRadius);
_shader->setUniform("isMonochromatic", (texture == nullptr || texture->getParent()->getNumChannels()) == 1);
FramebufferActivationGuard fag(this);
createAndAttachColorTexture();
glClearColor(0.1, 0.1, 0.1, 0.0);
glClear(GL_COLOR_BUFFER_BIT);
_grid->render(GL_TRIANGLE_STRIP);
_shader->deactivate();
LGL_ERROR;
data.addData(p_renderTargetID.getValue(), new RenderData(_fbo));
}
}
// ================================================================================================
//
// This file is part of the CAMPVis Software Framework.
//
// If not explicitly stated otherwise: Copyright (C) 2012-2014, all rights reserved,
// Christian Schulte zu Berge <christian.szb@in.tum.de>
// Chair for Computer Aided Medical Procedures
// Technische Universitaet Muenchen
// Boltzmannstr. 3, 85748 Garching b. Muenchen, Germany
//
// For a full list of authors and contributors, please refer to the file "AUTHORS.txt".
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
// except in compliance with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software distributed under the
// License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
// either express or implied. See the License for the specific language governing permissions
// and limitations under the License.
//
// ================================================================================================
#ifndef USFANRENDERER_H__
#define USFANRENDERER_H__
#include <string>
#include "core/pipeline/visualizationprocessor.h"
#include "core/pipeline/abstractprocessordecorator.h"
#include "core/properties/allproperties.h"
#include "core/datastructures/multiindexedgeometry.h"
namespace cgt {
class Shader;
}
namespace campvis {
class UsFanRenderer : public VisualizationProcessor {
public:
/**
* Constructs a new UsFanRenderer Processor
**/
UsFanRenderer(IVec2Property* viewportSizeProp);
/**
* Destructor
**/
virtual ~UsFanRenderer();
/// \see AbstractProcessor::init
virtual void init();
/// \see AbstractProcessor::deinit
virtual void deinit();
/// \see AbstractProcessor::getName()
virtual const std::string getName() const { return "UsFanRenderer"; };
/// \see AbstractProcessor::getDescription()
virtual const std::string getDescription() const { return "Enables to compute scan conversions of Ultrasound Images."; };
/// \see AbstractProcessor::getAuthor()
virtual const std::string getAuthor() const { return "Denis Declara <denis.declara@in.tum.de>"; };
/// \see AbstractProcessor::getProcessorState()
virtual ProcessorState getProcessorState() const { return AbstractProcessor::EXPERIMENTAL; };
DataNameProperty p_inputImage;
DataNameProperty p_renderTargetID;
FloatProperty p_halfAngle;
FloatProperty p_innerRadius;
protected:
/// \see AbstractProcessor::updateResult
virtual void updateResult(DataContainer& dataContainer);
cgt::Shader* _shader;
MultiIndexedGeometry *_grid;
private:
static const std::string loggerCat_;
};
}
#endif // USFANRENDERER_H__
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