Commit f0763803 authored by Christian Schulte zu Berge's avatar Christian Schulte zu Berge
Browse files

further work on StrainFiberRenderer, introducing tube rendering

parent 97fb9f3c
......@@ -95,7 +95,14 @@ vec4 applyTubeTexture(vec3 color) {
void main() {
vec4 color = applyTubeTexture(geom_Color.rbg);//vec4(geom_Normal, 1.0);
vec4 color;
#ifdef DO_STRIPES
color = applyTubeTexture(geom_Color.rbg);//vec4(geom_Normal, 1.0);
#endif
#ifdef DO_TUBES
color = geom_Color;
#endif
out_Color = color;
#ifdef ENABLE_SHADING
......@@ -106,4 +113,6 @@ void main() {
out_Color.rgb = calculatePhongShading(geom_Position.xyz / geom_Position.z, _lightSource, _cameraPosition, geom_Normal, color.rgb, color.rgb, vec3(1.0, 1.0, 1.0));
#endif
gl_FragDepth = gl_FragCoord.z;
}
......@@ -28,7 +28,16 @@
// ================================================================================================
layout (lines) in;
#ifdef DO_STRIPES
layout (triangle_strip, max_vertices = 4) out;
#endif
#ifdef DO_TUBES
#define NUM_SIDES 6
layout (triangle_strip, max_vertices = 14) out;
#endif
in vec3 vert_TexCoord[]; ///< incoming texture coordinate
in vec4 vert_Position[];
......@@ -42,8 +51,11 @@ out float geom_SineFlag;
uniform vec3 _cameraPosition;
uniform float _fiberWidth;
const float PI = 3.1415926535897932384626433832795;
void main() {
#ifdef DO_STRIPES
vec4 displacement[2];
vec3 normal[2];
......@@ -85,4 +97,52 @@ void main() {
EmitVertex();
EndPrimitive();
#endif
#ifdef DO_TUBES
mat3 rotMatrix[2];
for (int i = 0; i < 2; ++i) {
// calculate correct rotation matrix for pseudo-cylinder footprint:
vec3 rotBotZ = normalize(vert_TexCoord[i]); // already normalized!
bool degenerated = (rotBotZ.x == 0 && rotBotZ.z == 0);
vec3 rotBotX = degenerated ? vec3(1.f, 0.f, 0.f) : normalize(vec3(rotBotZ.z, 0.f, -rotBotZ.x));
vec3 rotBotY = degenerated ? vec3(0.f, 0.f, 1.f) : normalize(cross(rotBotZ, rotBotX));
rotMatrix[i] = mat3(rotBotX, rotBotY, rotBotZ);
}
vec3 normals[NUM_SIDES];
for (int i = 0; i < NUM_SIDES; ++i) {
float angle = float(i)/float(NUM_SIDES) * 2.0 * PI;
normals[i] = normalize(vec3(cos(angle) - sin(angle), sin(angle) + cos(angle), 0.0));
}
for (int i = 0; i < NUM_SIDES; ++i) {
geom_Color = vec4(vert_TexCoord[0], 1.0);
geom_Normal = normals[i] * rotMatrix[0];
geom_Position = vert_Position[0] + (vec4(geom_Normal, 0.0) * _fiberWidth);
gl_Position = geom_Position;
EmitVertex();
geom_Color = vec4(vert_TexCoord[1], 1.0);
geom_Normal = normals[i] * rotMatrix[1];
geom_Position = vert_Position[1] + (vec4(geom_Normal, 0.0) * _fiberWidth);
gl_Position = geom_Position;
EmitVertex();
}
geom_Color = vec4(vert_TexCoord[0], 1.0);
geom_Normal = normals[0] * rotMatrix[0];
geom_Position = vert_Position[0] + (vec4(geom_Normal, 0.0) * _fiberWidth);
gl_Position = geom_Position;
EmitVertex();
geom_Color = vec4(vert_TexCoord[1], 1.0);
geom_Normal = normals[0] * rotMatrix[1];
geom_Position = vert_Position[1] + (vec4(geom_Normal, 0.0) * _fiberWidth);
gl_Position = geom_Position;
EmitVertex();
EndPrimitive;
#endif
}
\ No newline at end of file
......@@ -43,6 +43,12 @@
#include "core/pipeline/processordecoratorshading.h"
namespace campvis {
static const GenericOption<StrainFiberRenderer::RenderMode> renderModeOptions[2] = {
GenericOption<StrainFiberRenderer::RenderMode>("Stripes", "Stripes", StrainFiberRenderer::STRIPES),
GenericOption<StrainFiberRenderer::RenderMode>("Tubes", "Tubes", StrainFiberRenderer::TUBES)
};
const std::string StrainFiberRenderer::loggerCat_ = "CAMPVis.modules.vis.StrainFiberRenderer";
StrainFiberRenderer::StrainFiberRenderer(IVec2Property& canvasSize)
......@@ -51,6 +57,7 @@ namespace campvis {
, p_renderTargetID("p_renderTargetID", "Output Image", "gr.output", DataNameProperty::WRITE)
, p_camera("Camera", "Camera ID")//, "camera", DataNameProperty::READ, AbstractProcessor::INVALID_RESULT, DataNameProperty::CameraData)
, p_lineWidth("LineWidth", "Line width", 3.f, .5f, 10.f)
, p_renderMode("RenderMode", "Render Mode", renderModeOptions, 2, AbstractProcessor::INVALID_RESULT | AbstractProcessor::INVALID_SHADER)
, p_color("color", "Rendering Color", tgt::vec4(1.f), tgt::vec4(0.f), tgt::vec4(1.f))
, _shader(0)
{
......@@ -60,6 +67,7 @@ namespace campvis {
addProperty(&p_renderTargetID);
addProperty(&p_camera);
addProperty(&p_color);
addProperty(&p_renderMode);
addProperty(&p_lineWidth);
decoratePropertyCollection(this);
......@@ -76,6 +84,7 @@ namespace campvis {
_shader->setAttributeLocation(0, "in_Position");
_shader->setAttributeLocation(1, "in_TexCoord");
}
invalidate(AbstractProcessor::INVALID_SHADER);
}
void StrainFiberRenderer::deinit() {
......@@ -85,14 +94,14 @@ namespace campvis {
}
void StrainFiberRenderer::process(DataContainer& data) {
if (hasInvalidShader()) {
_shader->setHeaders(generateGlslHeader());
_shader->rebuild();
validate(INVALID_SHADER);
}
DataContainer::ScopedTypedData<FiberData> strainData(data, p_strainId.getValue());
if (strainData != 0 && _shader != 0) {
if (hasInvalidShader()) {
_shader->setHeaders(generateGlslHeader());
_shader->rebuild();
validate(INVALID_SHADER);
}
const tgt::Camera& camera = p_camera.getValue();
// set modelview and projection matrices
......@@ -102,7 +111,7 @@ namespace campvis {
_shader->setUniform("_projectionMatrix", camera.getProjectionMatrix());
_shader->setUniform("_viewMatrix", camera.getViewMatrix());
_shader->setUniform("_cameraPosition", camera.getPosition());
_shader->setUniform("_fiberWidth", p_lineWidth.getValue());
_shader->setUniform("_fiberWidth", p_lineWidth.getValue()/4.f);
_shader->setIgnoreUniformLocationError(false);
// create entry points texture
......@@ -136,6 +145,17 @@ namespace campvis {
std::string StrainFiberRenderer::generateGlslHeader() const {
std::string toReturn = getDecoratedHeader();
switch (p_renderMode.getOptionValue()) {
case STRIPES:
toReturn += "#define DO_STRIPES\n";
break;
case TUBES:
toReturn += "#define DO_TUBES\n";
break;
}
return toReturn;
}
......
......@@ -38,6 +38,7 @@
#include "core/properties/datanameproperty.h"
#include "core/properties/genericproperty.h"
#include "core/properties/numericproperty.h"
#include "core/properties/optionproperty.h"
#include "core/properties/cameraproperty.h"
namespace tgt {
......@@ -50,6 +51,11 @@ namespace campvis {
*/
class StrainFiberRenderer : public VisualizationProcessor, public HasProcessorDecorators {
public:
enum RenderMode {
STRIPES,
TUBES
};
/**
* Constructs a new StrainFiberRenderer Processor
**/
......@@ -77,6 +83,7 @@ namespace campvis {
DataNameProperty p_renderTargetID; ///< image ID for output image
CameraProperty p_camera;
GenericOptionProperty<RenderMode> p_renderMode;
FloatProperty p_lineWidth;
Vec4Property p_color; ///< rendering color
......
......@@ -169,6 +169,7 @@ namespace campvis {
, p_strainId("StrainId", "Input Strain Data", "input", DataNameProperty::READ, AbstractProcessor::VALID)
, p_outputID("OutputId", "Output Fiber Data", "output", DataNameProperty::WRITE, AbstractProcessor::VALID)
, p_updateButton("UpdateButton", "Perform Tracking")
, p_seedDistance("SeedDistance", "Seed Distance", 4, 1, 16, AbstractProcessor::VALID)
, p_numSteps("NumSteps", "Maximum Number of Steps", 256, 16, 1024, AbstractProcessor::VALID)
, p_stepSize("StepSize", "Base Step Size", 1.f, .01f, 10.f, AbstractProcessor::VALID)
, p_strainThreshold("StrainThreshold", "Local Strain Threshold", .5f, .1f, 1.f, AbstractProcessor::VALID)
......@@ -177,6 +178,7 @@ namespace campvis {
addProperty(&p_strainId);
addProperty(&p_outputID);
addProperty(&p_updateButton);
addProperty(&p_seedDistance);
addProperty(&p_numSteps);
addProperty(&p_stepSize);
addProperty(&p_strainThreshold);
......@@ -223,10 +225,11 @@ namespace campvis {
std::vector<tgt::vec3> seeds;
const tgt::mat4& VtW = strainData.getParent()->getMappingInformation().getVoxelToWorldMatrix();
float threshold = p_strainThreshold.getValue() * p_strainThreshold.getValue();
int inc = p_seedDistance.getValue();
for (size_t z = 0; z < strainData.getSize().z; z += 2) {
for (size_t y = 0; y < strainData.getSize().y; y += 2) {
for (size_t x = 0; x < strainData.getSize().x; x += 2) {
for (size_t z = 0; z < strainData.getSize().z; z += inc) {
for (size_t y = 0; y < strainData.getSize().y; y += inc) {
for (size_t x = 0; x < strainData.getSize().x; x += inc) {
tgt::vec3 pos(x, y, z);
if (tgt::lengthSq(getVec3FloatLinear(strainData, pos)) > threshold) {
seeds.push_back((VtW * tgt::vec4(pos, 1.f)).xyz());
......
......@@ -72,6 +72,8 @@ namespace campvis {
ButtonProperty p_updateButton; ///< Button to start tracking
IntProperty p_seedDistance;
IntProperty p_numSteps; ///< Maximum number of steps per fiber
FloatProperty p_stepSize; ///< Base step size
......
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