Notice to GitKraken users: A vulnerability has been found in the SSH key generation of GitKraken versions 7.6.0 to 8.0.0 (https://www.gitkraken.com/blog/weak-ssh-key-fix). If you use GitKraken and have generated a SSH key using one of these versions, please remove it both from your local workstation and from your LRZ GitLab profile.

21.10.2021, 9:00 - 11:00: Due to updates GitLab may be unavailable for some minutes between 09:00 and 11:00.

Commit 6e9d3b08 authored by schultezub's avatar schultezub
Browse files

implemented arbitrary axis slice rendering for SliceExtractor

git-svn-id: https://camplinux.in.tum.de/svn/campvis/trunk@495 bb408c1c-ae56-11e1-83d9-df6b3e0c105e
parent 232d1722
......@@ -134,6 +134,8 @@ namespace campvis {
}
while (_pause > 0) {
GLGC.deleteGarbage();
lastCleanupTime = clock();
CtxtMgr.releaseCurrentContext();
_evaluationCondition.wait(lock);
_currentContext->getContext()->acquire();
......@@ -141,6 +143,8 @@ namespace campvis {
}
if (! hadWork) {
GLGC.deleteGarbage();
lastCleanupTime = clock();
CtxtMgr.releaseCurrentContext();
_evaluationCondition.wait(lock);
_currentContext->getContext()->acquire();
......
......@@ -33,17 +33,19 @@ in vec3 ex_TexCoord;
out vec4 out_Color;
//#include "tools/background.frag"
#include "tools/texture2d.frag"
#include "tools/texture3d.frag"
#include "tools/transferfunction.frag"
uniform sampler2D _texture;
uniform TextureParameters2D _textureParams;
uniform sampler3D _texture;
uniform TextureParameters3D _textureParams;
uniform sampler1D _transferFunction;
uniform TFParameters1D _transferFunctionParams;
uniform mat4 _texCoordsMatrix;
void main() {
vec4 texel = getElement2DNormalized(_texture, _textureParams, ex_TexCoord.xy);
vec4 texel = getElement3DNormalized(_texture, _textureParams, (_texCoordsMatrix * vec4(ex_TexCoord, 1.0)).xyz);
if (_textureParams._numChannels == 1) {
out_Color = lookupTF(_transferFunction, _transferFunctionParams, texel.a);
......
......@@ -42,7 +42,7 @@ namespace campvis {
, _gvg()
, _lhh()
, _sliceExtractor(_effectiveRenderTargetSize)
, _wheelHandler(&_sliceExtractor.p_sliceNumber)
, _wheelHandler(&_sliceExtractor.p_zSliceNumber)
, _tfWindowingHandler(&_sliceExtractor.p_transferFunction)
{
addProcessor(&_imageReader);
......@@ -68,7 +68,7 @@ namespace campvis {
// _gvg._outputGradients.connect(&_lhh._inputGradients);
_sliceExtractor.p_sliceNumber.setValue(0);
_sliceExtractor.p_xSliceNumber.setValue(0);
// TODO: replace this hardcoded domain by automatically determined from image min/max values
Geometry1DTransferFunction* tf = new Geometry1DTransferFunction(128, tgt::vec2(0.f, .08f));
......@@ -83,10 +83,10 @@ namespace campvis {
if (e->pressed()) {
switch (e->keyCode()) {
case tgt::KeyEvent::K_UP:
_sliceExtractor.p_sliceNumber.increment();
_sliceExtractor.p_xSliceNumber.increment();
break;
case tgt::KeyEvent::K_DOWN:
_sliceExtractor.p_sliceNumber.decrement();
_sliceExtractor.p_xSliceNumber.decrement();
break;
}
}
......
......@@ -42,19 +42,31 @@
#include "core/tools/quadrenderer.h"
namespace campvis {
static const GenericOption<SliceExtractor::SliceOrientation> compositingOptions[3] = {
GenericOption<SliceExtractor::SliceOrientation>("z", "XY Plane", SliceExtractor::XY_PLANE),
GenericOption<SliceExtractor::SliceOrientation>("y", "XZ Plane", SliceExtractor::XZ_PLANE),
GenericOption<SliceExtractor::SliceOrientation>("x", "YZ Plane", SliceExtractor::YZ_PLANE)
};
const std::string SliceExtractor::loggerCat_ = "CAMPVis.modules.vis.SliceExtractor";
SliceExtractor::SliceExtractor(IVec2Property& canvasSize)
: VisualizationProcessor(canvasSize)
, p_sourceImageID("sourceImageID", "Input Image", "", DataNameProperty::READ)
, p_sourceImageID("sourceImageID", "Input Image", "", DataNameProperty::READ, AbstractProcessor::INVALID_PROPERTIES)
, p_targetImageID("targetImageID", "Output Image", "", DataNameProperty::WRITE)
, p_sliceNumber("sliceNumber", "Slice Number", 0, 0, 0)
, p_sliceOrientation("SliceOrientation", "Slice Orientation", compositingOptions, 3)
, p_xSliceNumber("XSliceNumber", "X Slice Number", 0, 0, 0)
, p_ySliceNumber("YSliceNumber", "Y Slice Number", 0, 0, 0)
, p_zSliceNumber("ZSliceNumber", "Z Slice Number", 0, 0, 0)
, p_transferFunction("transferFunction", "Transfer Function", new SimpleTransferFunction(256))
, _shader(0)
{
addProperty(&p_sourceImageID);
addProperty(&p_targetImageID);
addProperty(&p_sliceNumber);
addProperty(&p_sliceOrientation);
addProperty(&p_xSliceNumber);
addProperty(&p_ySliceNumber);
addProperty(&p_zSliceNumber);
addProperty(&p_transferFunction);
//addDecorator(new ProcessorDecoratorBackground());
......@@ -78,27 +90,49 @@ namespace campvis {
}
void SliceExtractor::process(DataContainer& data) {
DataContainer::ScopedTypedData<ImageData> img(data, p_sourceImageID.getValue());
ImageRepresentationGL::ScopedRepresentation img(data, p_sourceImageID.getValue());
if (img != 0) {
if (img->getDimensionality() == 3) {
if (img.getDataHandle().getTimestamp() != _sourceImageTimestamp) {
if (hasInvalidProperties()) {
// source DataHandle has changed
updateProperties(img.getDataHandle());
_sourceImageTimestamp = img.getDataHandle().getTimestamp();
validate(AbstractProcessor::INVALID_PROPERTIES);
}
const tgt::svec3& imgSize = img->getSize();
ImageData* slice = img->getSubImage(tgt::svec3(0, 0, p_sliceNumber.getValue()), tgt::svec3(imgSize.x, imgSize.y, p_sliceNumber.getValue()+1));
const ImageRepresentationGL* glData = slice->getRepresentation<ImageRepresentationGL>();
std::pair<ImageData*, ImageRepresentationRenderTarget*> rt = ImageRepresentationRenderTarget::createWithImageData(_renderTargetSize.getValue());
tgt::mat4 texCoordsMatrix = tgt::mat4::zero;
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));
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;
texCoordsMatrix.t13 = (static_cast<float>(p_ySliceNumber.getValue() + 0.5f) / static_cast<float>(imgSize.y));
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));
break;
}
_shader->activate();
decorateRenderProlog(data, _shader);
tgt::TextureUnit inputUnit, tfUnit;
glData->bind(_shader, inputUnit);
img->bind(_shader, inputUnit);
p_transferFunction.getTF()->bind(_shader, tfUnit);
_shader->setUniform("_texCoordsMatrix", texCoordsMatrix);
rt.second->activate();
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
......@@ -111,7 +145,6 @@ namespace campvis {
data.addData(p_targetImageID.getValue(), rt.first);
p_targetImageID.issueWrite();
delete slice;
}
else {
LERROR("Input image must have dimensionality of 3.");
......@@ -127,8 +160,14 @@ namespace campvis {
void SliceExtractor::updateProperties(DataHandle img) {
p_transferFunction.getTF()->setImageHandle(img);
const tgt::svec3& imgSize = static_cast<const ImageData*>(img.getData())->getSize();
if (p_sliceNumber.getMaxValue() != imgSize.z - 1){
p_sliceNumber.setMaxValue(static_cast<int>(imgSize.z) - 1);
if (p_xSliceNumber.getMaxValue() != imgSize.x - 1){
p_xSliceNumber.setMaxValue(static_cast<int>(imgSize.x) - 1);
}
if (p_ySliceNumber.getMaxValue() != imgSize.y - 1){
p_ySliceNumber.setMaxValue(static_cast<int>(imgSize.y) - 1);
}
if (p_zSliceNumber.getMaxValue() != imgSize.z - 1){
p_zSliceNumber.setMaxValue(static_cast<int>(imgSize.z) - 1);
}
}
......
......@@ -36,6 +36,7 @@
#include "core/pipeline/visualizationprocessor.h"
#include "core/properties/datanameproperty.h"
#include "core/properties/genericproperty.h"
#include "core/properties/optionproperty.h"
#include "core/properties/numericproperty.h"
#include "core/properties/transferfunctionproperty.h"
......@@ -51,6 +52,12 @@ namespace campvis {
*/
class SliceExtractor : public VisualizationProcessor, public HasProcessorDecorators {
public:
enum SliceOrientation {
XY_PLANE = 0,
XZ_PLANE = 1,
YZ_PLANE = 2
};
/**
* Constructs a new SliceExtractor Processor
**/
......@@ -78,11 +85,14 @@ namespace campvis {
DataNameProperty p_sourceImageID; ///< image ID for input image
DataNameProperty p_targetImageID; ///< image ID for output image
IntProperty p_sliceNumber; ///< number of the slice to extract
GenericOptionProperty<SliceOrientation> p_sliceOrientation; ///< orientation of the slice to extract
IntProperty p_xSliceNumber; ///< number of the slice in X direction
IntProperty p_ySliceNumber; ///< number of the slice in Y direction
IntProperty p_zSliceNumber; ///< number of the slice in Z direction
TransferFunctionProperty p_transferFunction; ///< Transfer function
protected:
/// adapts the range of the p_sliceNumber property to the image
/// adapts the range of the p_xSliceNumber property to the image
void updateProperties(DataHandle img);
tgt::Shader* _shader; ///< Shader for slice rendering
......
......@@ -56,6 +56,7 @@ namespace campvis {
addProperty(&_raycaster.p_transferFunction);
addProperty(&_raycaster.p_samplingRate);
addProperty(&p_outputImage);
addProperty(_raycaster.getProperty("CentralDifferences"));
// setup shared properties
p_inputVolume.addSharedProperty(&_pgGenerator.p_sourceImageID);
......
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