Commit c1597c93 authored by schultezub's avatar schultezub

* added selectable render mode to GeometryData

* added slice marker rendering to SliceExtractor

git-svn-id: https://camplinux.in.tum.de/svn/campvis/trunk@497 bb408c1c-ae56-11e1-83d9-df6b3e0c105e
parent c980f2ed
......@@ -184,7 +184,7 @@ namespace campvis {
}
_paintShader->setIgnoreUniformLocationError(false);
_quad->render();
_quad->render(GL_POLYGON);
}
void DataContainerInspectorCanvas::invalidate() {
......
......@@ -103,7 +103,7 @@ namespace campvis {
return _faceNormal;
}
void FaceGeometry::render() const {
void FaceGeometry::render(GLenum mode) const {
createGLBuffers();
if (! _buffersInitialized) {
LERROR("Cannot render without initialized OpenGL buffers.");
......@@ -121,10 +121,7 @@ namespace campvis {
vao.addVertexAttribute(tgt::VertexArrayObject::NormalsAttribute, _normalsBuffer);
LGL_ERROR;
if (_vertices.size() > 2)
glDrawArrays(GL_POLYGON, 0, static_cast<GLsizei>(_vertices.size()));
else
glDrawArrays(GL_LINES, 0, static_cast<GLsizei>(_vertices.size()));
glDrawArrays(mode, 0, static_cast<GLsizei>(_vertices.size()));
LGL_ERROR;
}
......
......@@ -128,8 +128,9 @@ namespace campvis {
/**
* Renders this FaceGeometry.
* Must be called from a valid OpenGL context.
* \param mode OpenGL rendering mode for this face
*/
virtual void render() const;
virtual void render(GLenum mode) const;
/**
* Creates the OpenGL VBOs and the VAO for this face's geometry.
......
......@@ -30,6 +30,7 @@
#ifndef GEOMETRYDATA_H__
#define GEOMETRYDATA_H__
#include "tgt/tgt_gl.h"
#include "core/datastructures/abstractdata.h"
#include <vector>
......@@ -68,7 +69,7 @@ namespace campvis {
* Renders this GeometryData.
* Must be called from a valid OpenGL context.
*/
virtual void render() const = 0;
virtual void render(GLenum mode = GL_POLYGON) const = 0;
/**
* Creates the OpenGL VBOs and the VAO for this geometry.
......
......@@ -82,7 +82,7 @@ namespace campvis {
}
void MeshGeometry::render() const {
void MeshGeometry::render(GLenum mode) const {
createGLBuffers();
if (! _buffersInitialized) {
LERROR("Cannot render without initialized OpenGL buffers.");
......@@ -104,7 +104,7 @@ namespace campvis {
for (std::vector<FaceGeometry>::const_iterator it = _faces.begin(); it != _faces.end(); ++it) {
GLsizei numVertices = static_cast<GLsizei>(it->getVertices().size());
if (numVertices > 2)
glDrawArrays(GL_POLYGON, startIndex, numVertices);
glDrawArrays(mode, startIndex, numVertices);
else
glDrawArrays(GL_LINES, startIndex, numVertices);
startIndex += numVertices;
......
......@@ -95,8 +95,9 @@ namespace campvis {
/**
* Renders this MeshGeometry.
* Must be called from a valid OpenGL context.
* \param mode OpenGL rendering mode for this mesh
*/
virtual void render() const;
virtual void render(GLenum mode) const;
/**
* Creates the OpenGL VBOs and the VAO for this face's geometry.
......
......@@ -56,8 +56,8 @@ namespace campvis {
delete _quad;
}
void QuadRenderer::renderQuad() {
_quad->render();
void QuadRenderer::renderQuad(GLenum mode) {
_quad->render(mode);
}
......
......@@ -50,7 +50,7 @@ namespace campvis {
*/
virtual ~QuadRenderer();
void renderQuad();
void renderQuad(GLenum mode = GL_POLYGON);
private:
QuadRenderer();
......
......@@ -44,20 +44,24 @@ uniform TFParameters1D _transferFunctionParams;
uniform mat4 _texCoordsMatrix;
uniform bool _useTexturing;
uniform vec4 _color;
void main() {
vec4 texel = getElement3DNormalized(_texture, _textureParams, (_texCoordsMatrix * vec4(ex_TexCoord, 1.0)).xyz);
if (_useTexturing) {
vec4 texel = getElement3DNormalized(_texture, _textureParams, (_texCoordsMatrix * vec4(ex_TexCoord, 1.0)).xyz);
if (_textureParams._numChannels == 1) {
out_Color = lookupTF(_transferFunction, _transferFunctionParams, texel.a);
}
else if (_textureParams._numChannels == 3) {
out_Color = vec4(abs(texel.rgb), 1.0);
}
else if (_textureParams._numChannels == 4) {
out_Color = (abs(texel) - vec4(_transferFunctionParams._intensityDomain.x)) / (_transferFunctionParams._intensityDomain.y - _transferFunctionParams._intensityDomain.x);
if (_textureParams._numChannels == 1) {
out_Color = lookupTF(_transferFunction, _transferFunctionParams, texel.a);
}
else if (_textureParams._numChannels == 3) {
out_Color = vec4(abs(texel.rgb), 1.0);
}
else if (_textureParams._numChannels == 4) {
out_Color = (abs(texel) - vec4(_transferFunctionParams._intensityDomain.x)) / (_transferFunctionParams._intensityDomain.y - _transferFunctionParams._intensityDomain.x);
}
}
//if (out_Color.a == 0) {
// renderBackground(ex_TexCoord.xy, out_Color);
//}
else {
out_Color = _color;
}
}
......@@ -183,7 +183,7 @@ namespace campvis {
glClearDepth(1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glCullFace(p_enableMirror.getValue() ? GL_FRONT : GL_BACK);
clipped.render();
clipped.render(GL_POLYGON);
entrypoints.second->deactivate();
......@@ -200,7 +200,7 @@ namespace campvis {
glClearDepth(0.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glCullFace(p_enableMirror.getValue() ? GL_BACK : GL_FRONT);
clipped.render();
clipped.render(GL_POLYGON);
exitpoints.second->deactivate();
......
......@@ -32,6 +32,7 @@
#include "tgt/shadermanager.h"
#include "tgt/textureunit.h"
#include "core/datastructures/facegeometry.h"
#include "core/datastructures/imagedata.h"
#include "core/datastructures/imagerepresentationgl.h"
#include "core/datastructures/imagerepresentationrendertarget.h"
......@@ -55,9 +56,12 @@ namespace campvis {
, p_sourceImageID("sourceImageID", "Input Image", "", DataNameProperty::READ, AbstractProcessor::INVALID_PROPERTIES)
, p_targetImageID("targetImageID", "Output Image", "", DataNameProperty::WRITE)
, p_sliceOrientation("SliceOrientation", "Slice Orientation", compositingOptions, 3)
, p_xSliceNumber("XSliceNumber", "X Slice Number", 0, 0, 0)
, p_xSliceNumber("XSliceNumber", "X Slice Number", 0, 0, 0)
, p_xSliceColor("XSliceColor", "X Slice Color", tgt::vec4(1.f, 0.f, 0.f, 1.f), tgt::vec4(0.f), tgt::vec4(1.f))
, p_ySliceNumber("YSliceNumber", "Y Slice Number", 0, 0, 0)
, p_ySliceColor("YSliceColor", "Y Slice Color", tgt::vec4(0.f, 1.f, 0.f, 1.f), tgt::vec4(0.f), tgt::vec4(1.f))
, p_zSliceNumber("ZSliceNumber", "Z Slice Number", 0, 0, 0)
, p_zSliceColor("ZSliceColor", "Z Slice Color", tgt::vec4(0.f, 0.f, 1.f, 1.f), tgt::vec4(0.f), tgt::vec4(1.f))
, p_transferFunction("transferFunction", "Transfer Function", new SimpleTransferFunction(256))
, _shader(0)
{
......@@ -65,8 +69,11 @@ namespace campvis {
addProperty(&p_targetImageID);
addProperty(&p_sliceOrientation);
addProperty(&p_xSliceNumber);
addProperty(&p_xSliceColor);
addProperty(&p_ySliceNumber);
addProperty(&p_ySliceColor);
addProperty(&p_zSliceNumber);
addProperty(&p_zSliceColor);
addProperty(&p_transferFunction);
//addDecorator(new ProcessorDecoratorBackground());
......@@ -100,59 +107,140 @@ namespace campvis {
validate(AbstractProcessor::INVALID_PROPERTIES);
}
const tgt::svec3& imgSize = img->getSize();
std::pair<ImageData*, ImageRepresentationRenderTarget*> rt = ImageRepresentationRenderTarget::createWithImageData(_renderTargetSize.getValue());
tgt::vec3 imgSize(img->getSize());
// current slices in texture coordinates
tgt::vec3 sliceTexCoord = tgt::vec3(.5f + p_xSliceNumber.getValue(), .5f + p_ySliceNumber.getValue(), .5f + p_zSliceNumber.getValue()) / imgSize;
// texture coordinate transformation matrix (will be configured later)
tgt::mat4 texCoordsMatrix = tgt::mat4::zero;
float renderTargetRatio = static_cast<float>(_renderTargetSize.getValue().x) / static_cast<float>(_renderTargetSize.getValue().y);
float sliceRatio = 1.f;
switch (p_sliceOrientation.getValue()) {
case XY_PLANE:
texCoordsMatrix = tgt::mat4::identity;
texCoordsMatrix.t23 = (static_cast<float>(p_zSliceNumber.getValue() + 0.5f) / static_cast<float>(imgSize.z));
sliceRatio =
(static_cast<float>(imgSize.x) * img.getImageData()->getMappingInformation().getVoxelSize().x)
/ (static_cast<float>(imgSize.y) * img.getImageData()->getMappingInformation().getVoxelSize().y);
break;
case XZ_PLANE:
texCoordsMatrix.t00 = 1.f; // setup a permutation matrix, swapping z- and y-
texCoordsMatrix.t12 = 1.f; // components on vectors being multiplied with it
texCoordsMatrix.t21 = 1.f;
texCoordsMatrix.t33 = 1.f;
sliceRatio = static_cast<float>(imgSize.x) / static_cast<float>(imgSize.y);
texCoordsMatrix.t13 = (static_cast<float>(p_ySliceNumber.getValue() + 0.5f) / static_cast<float>(imgSize.y));
sliceRatio =
(static_cast<float>(imgSize.x) * img.getImageData()->getMappingInformation().getVoxelSize().x)
/ (static_cast<float>(imgSize.z) * img.getImageData()->getMappingInformation().getVoxelSize().z);
break;
case YZ_PLANE:
texCoordsMatrix.t01 = 1.f; // setup a permutation matrix, swapping x-, y- and z-
texCoordsMatrix.t12 = 1.f; // components on vectors being multiplied with it
texCoordsMatrix.t20 = 1.f;
texCoordsMatrix.t33 = 1.f;
texCoordsMatrix.t13 = (static_cast<float>(p_xSliceNumber.getValue() + 0.5f) / static_cast<float>(imgSize.x));
sliceRatio =
(static_cast<float>(imgSize.y) * img.getImageData()->getMappingInformation().getVoxelSize().y)
/ (static_cast<float>(imgSize.z) * img.getImageData()->getMappingInformation().getVoxelSize().z);
break;
case XY_PLANE:
texCoordsMatrix.t00 = 1.f;
texCoordsMatrix.t11 = 1.f;
texCoordsMatrix.t22 = 1.f;
//texCoordsMatrix.t13 = 1.f;
texCoordsMatrix.t23 = sliceTexCoord.z;
sliceRatio =
(static_cast<float>(imgSize.x) * img.getImageData()->getMappingInformation().getVoxelSize().x)
/ (static_cast<float>(imgSize.y) * img.getImageData()->getMappingInformation().getVoxelSize().y);
break;
case XZ_PLANE:
texCoordsMatrix.t00 = 1.f;
texCoordsMatrix.t12 = 1.f;
texCoordsMatrix.t21 = 1.f;
texCoordsMatrix.t33 = 1.f;
texCoordsMatrix.t13 = sliceTexCoord.y;
sliceRatio =
(static_cast<float>(imgSize.x) * img.getImageData()->getMappingInformation().getVoxelSize().x)
/ (static_cast<float>(imgSize.z) * img.getImageData()->getMappingInformation().getVoxelSize().z);
break;
case YZ_PLANE:
texCoordsMatrix.t02 = 1.f;
texCoordsMatrix.t10 = 1.f;
texCoordsMatrix.t21 = 1.f;
//texCoordsMatrix.t13 = 0.f;
texCoordsMatrix.t33 = 1.f;
texCoordsMatrix.t03 = sliceTexCoord.x;
sliceRatio =
(static_cast<float>(imgSize.y) * img.getImageData()->getMappingInformation().getVoxelSize().y)
/ (static_cast<float>(imgSize.z) * img.getImageData()->getMappingInformation().getVoxelSize().z);
break;
}
// configure model matrix so that slices are rendered with correct aspect ratio
float ratioRatio = sliceRatio / renderTargetRatio;
tgt::mat4 modelMatrix = (ratioRatio > 1) ? tgt::mat4::createScale(tgt::vec3(1.f, 1.f / ratioRatio, 1.f)) : tgt::mat4::createScale(tgt::vec3(ratioRatio, 1.f, 1.f));
// prepare OpenGL
std::pair<ImageData*, ImageRepresentationRenderTarget*> rt = ImageRepresentationRenderTarget::createWithImageData(_renderTargetSize.getValue());
_shader->activate();
decorateRenderProlog(data, _shader);
tgt::TextureUnit inputUnit, tfUnit;
img->bind(_shader, inputUnit);
p_transferFunction.getTF()->bind(_shader, tfUnit);
// render slice
_shader->setUniform("_texCoordsMatrix", texCoordsMatrix);
_shader->setUniform("_modelMatrix", modelMatrix);
_shader->setUniform("_useTexturing", true);
rt.second->activate();
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
QuadRdr.renderQuad();
// render slice markers
glLineWidth(2.f);
_shader->setUniform("_useTexturing", false);
switch (p_sliceOrientation.getValue()) {
case XY_PLANE:
_shader->setUniform("_color", p_zSliceColor.getValue());
QuadRdr.renderQuad(GL_LINE_LOOP);
modelMatrix.t00 = 0.f;
modelMatrix.t03 = 2.f * sliceTexCoord.x - 1.f;
modelMatrix.t03 *= (ratioRatio > 1) ? 1.f : ratioRatio;
_shader->setUniform("_modelMatrix", modelMatrix);
_shader->setUniform("_color", p_xSliceColor.getValue());
QuadRdr.renderQuad(GL_LINE_STRIP);
modelMatrix.t00 = (ratioRatio > 1) ? 1.f : ratioRatio;
modelMatrix.t11 = 0.f;
modelMatrix.t03 = 0.f;
modelMatrix.t13 = 2.f * sliceTexCoord.y - 1.f;
modelMatrix.t13 *= (ratioRatio > 1) ? 1.f : ratioRatio;
_shader->setUniform("_modelMatrix", modelMatrix);
_shader->setUniform("_color", p_ySliceColor.getValue());
QuadRdr.renderQuad(GL_LINE_STRIP);
break;
case XZ_PLANE:
_shader->setUniform("_color", p_ySliceColor.getValue());
QuadRdr.renderQuad(GL_LINE_LOOP);
modelMatrix.t00 = 0.f;
modelMatrix.t03 = 2.f * sliceTexCoord.x - 1.f;
modelMatrix.t03 *= (ratioRatio > 1) ? 1.f : ratioRatio;
_shader->setUniform("_modelMatrix", modelMatrix);
_shader->setUniform("_color", p_xSliceColor.getValue());
QuadRdr.renderQuad(GL_LINE_STRIP);
modelMatrix.t00 = (ratioRatio > 1) ? 1.f : ratioRatio;
modelMatrix.t11 = 0.f;
modelMatrix.t03 = 0.f;
modelMatrix.t13 = 2.f * sliceTexCoord.z - 1.f;
modelMatrix.t13 *= (ratioRatio > 1) ? 1.f / ratioRatio : 1.f;
_shader->setUniform("_modelMatrix", modelMatrix);
_shader->setUniform("_color", p_zSliceColor.getValue());
QuadRdr.renderQuad(GL_LINE_STRIP);
break;
case YZ_PLANE:
_shader->setUniform("_color", p_xSliceColor.getValue());
QuadRdr.renderQuad(GL_LINE_LOOP);
modelMatrix.t00 = 0.f;
modelMatrix.t03 = 2.f * sliceTexCoord.y - 1.f;
modelMatrix.t03 *= (ratioRatio > 1) ? 1.f : ratioRatio;
_shader->setUniform("_modelMatrix", modelMatrix);
_shader->setUniform("_color", p_ySliceColor.getValue());
QuadRdr.renderQuad(GL_LINE_STRIP);
modelMatrix.t00 = (ratioRatio > 1) ? 1.f : ratioRatio;
modelMatrix.t11 = 0.f;
modelMatrix.t03 = 0.f;
modelMatrix.t13 = 2.f * sliceTexCoord.z - 1.f;
modelMatrix.t13 *= (ratioRatio > 1) ? 1.f / ratioRatio : 1.f;
_shader->setUniform("_modelMatrix", modelMatrix);
_shader->setUniform("_color", p_zSliceColor.getValue());
QuadRdr.renderQuad(GL_LINE_STRIP);
break;
}
rt.second->deactivate();
decorateRenderEpilog(_shader);
......@@ -187,4 +275,7 @@ namespace campvis {
}
}
void SliceExtractor::updateBorderGeometry() {
}
}
......@@ -32,6 +32,9 @@
#include <string>
#include "tgt/buffer.h"
#include "tgt/vertexarrayobject.h"
#include "core/pipeline/abstractprocessordecorator.h"
#include "core/pipeline/visualizationprocessor.h"
#include "core/properties/datanameproperty.h"
......@@ -45,6 +48,7 @@ namespace tgt {
}
namespace campvis {
class FaceGeometry;
class ImageData;
/**
......@@ -87,14 +91,19 @@ namespace campvis {
GenericOptionProperty<SliceOrientation> p_sliceOrientation; ///< orientation of the slice to extract
IntProperty p_xSliceNumber; ///< number of the slice in X direction
Vec4Property p_xSliceColor; ///< color for x marker
IntProperty p_ySliceNumber; ///< number of the slice in Y direction
Vec4Property p_ySliceColor; ///< color for y marker
IntProperty p_zSliceNumber; ///< number of the slice in Z direction
Vec4Property p_zSliceColor; ///< color for z marker
TransferFunctionProperty p_transferFunction; ///< Transfer function
protected:
/// adapts the range of the p_xSliceNumber property to the image
void updateProperties(DataHandle img);
void updateBorderGeometry();
tgt::Shader* _shader; ///< Shader for slice rendering
static const std::string loggerCat_;
......
......@@ -120,7 +120,7 @@ namespace campvis {
rt.second->activate();
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
slice.render();
slice.render(GL_POLYGON);
rt.second->deactivate();
_shader->deactivate();
......
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