Introducing GlImageCrop processor to preprocessing module.

parent 2e58b886
// ================================================================================================
//
// 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 ex_TexCoord;
out vec4 out_Color;
#include "tools/gradient.frag"
#include "tools/texture3d.frag"
#include "tools/transferfunction.frag"
uniform sampler3D _texture;
uniform TextureParameters3D _textureParams;
uniform ivec3 _outputSize;
uniform ivec3 _offset;
uniform int _zTexel;
void main() {
//ivec2 texel = ivec2(((1.0 / vec2(_outputSize.xy)) + ex_TexCoord.xy) * vec2(_outputSize.xy));
ivec2 texel = ivec2(ex_TexCoord.xy * vec2(_outputSize.xy));
vec4 intensity = texelFetch(_texture, ivec3(texel, _zTexel) + _offset, 0);
out_Color = intensity;
}
// ================================================================================================
//
// 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 "glimagecrop.h"
#include "cgt/logmanager.h"
#include "cgt/shadermanager.h"
#include "cgt/textureunit.h"
#include "cgt/texture.h"
#include "core/classification/geometry1dtransferfunction.h"
#include "core/classification/tfgeometry1d.h"
#include "core/datastructures/imagedata.h"
#include "core/datastructures/imagerepresentationgl.h"
#include "core/datastructures/renderdata.h"
#include "core/tools/quadrenderer.h"
namespace campvis {
const std::string GlImageCrop::loggerCat_ = "CAMPVis.modules.classification.GlImageCrop";
GlImageCrop::GlImageCrop(IVec2Property* viewportSizeProp)
: VisualizationProcessor(viewportSizeProp)
, p_inputImage("InputImage", "Input Image", "", DataNameProperty::READ)
, p_outputImage("OutputImage", "Output Image", "GlImageCrop.out", DataNameProperty::WRITE)
, p_llf("Llf", "LLF of Cropped Region", cgt::ivec3(0), cgt::ivec3(0), cgt::ivec3(1))
, p_urb("Urb", "URB of Cropped Region", cgt::ivec3(1), cgt::ivec3(0), cgt::ivec3(1))
{
addProperty(p_inputImage, INVALID_PROPERTIES | INVALID_RESULT);
addProperty(p_outputImage);
addProperty(p_llf);
addProperty(p_urb);
}
GlImageCrop::~GlImageCrop() {
}
void GlImageCrop::init() {
VisualizationProcessor::init();
_shader = ShdrMgr.load("core/glsl/passthrough.vert", "modules/preprocessing/glsl/glimagecrop.frag", "");
_shader->setAttributeLocation(0, "in_Position");
_shader->setAttributeLocation(1, "in_TexCoord");
}
void GlImageCrop::deinit() {
ShdrMgr.dispose(_shader);
VisualizationProcessor::deinit();
}
void GlImageCrop::updateResult(DataContainer& data) {
ImageRepresentationGL::ScopedRepresentation img(data, p_inputImage.getValue());
if (img != 0) {
cgt::ivec3 inputSize = img->getSize();
cgt::ivec3 outputSize = cgt::abs(p_urb.getValue() - p_llf.getValue());
cgt::TextureUnit inputUnit;
inputUnit.activate();
// create texture for result
cgt::Texture* resultTexture = new cgt::Texture(0, outputSize, img->getTexture()->getFormat(), img->getTexture()->getInternalFormat(), img->getTexture()->getDataType(), cgt::Texture::LINEAR);
resultTexture->uploadTexture();
// activate shader and bind textures
_shader->activate();
_shader->setUniform("_offset", p_llf.getValue());
_shader->setUniform("_outputSize", outputSize);
img->bind(_shader, inputUnit);
// activate FBO and attach texture
_fbo->activate();
glViewport(0, 0, static_cast<GLsizei>(outputSize.x), static_cast<GLsizei>(outputSize.y));
// render quad to compute difference measure by shader
for (int z = 0; z < outputSize.z; ++z) {
_shader->setUniform("_zTexel", z);
_fbo->attachTexture(resultTexture, GL_COLOR_ATTACHMENT0, 0, z);
QuadRdr.renderQuad();
}
_fbo->detachAll();
_fbo->deactivate();
_shader->deactivate();
// put resulting image into DataContainer
ImageData* id = new ImageData(3, outputSize, img.getImageData()->getNumChannels());
ImageRepresentationGL::create(id, resultTexture);
const ImageMappingInformation& imi = img->getParent()->getMappingInformation();
id->setMappingInformation(ImageMappingInformation(img->getSize(), imi.getOffset() + (cgt::vec3(p_llf.getValue()) * imi.getVoxelSize()), imi.getVoxelSize(), imi.getRealWorldMapping()));
data.addData(p_outputImage.getValue(), id);
cgt::TextureUnit::setZeroUnit();
LGL_ERROR;
}
else {
LDEBUG("No suitable input image found.");
}
}
void GlImageCrop::updateProperties(DataContainer& dataContainer) {
ImageRepresentationGL::ScopedRepresentation img(dataContainer, p_inputImage.getValue());
if (img != nullptr) {
cgt::ivec3 size(img->getSize());
if (p_llf.getMaxValue() != size-1)
p_llf.setMaxValue(size-1);
if (p_urb.getMaxValue() != size) {
p_urb.setMaxValue(size);
p_urb.setValue(size);
}
}
}
}
// ================================================================================================
//
// 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 GLIMAGECROP_H__
#define GLIMAGECROP_H__
#include <string>
#include "core/pipeline/abstractprocessordecorator.h"
#include "core/pipeline/visualizationprocessor.h"
#include "core/properties/datanameproperty.h"
#include "core/properties/transferfunctionproperty.h"
#include "core/properties/numericproperty.h"
namespace cgt {
class Shader;
}
namespace campvis {
/**
* Quantizes image intensities into a fixed number of bins using the GPU.
*/
class GlImageCrop : public VisualizationProcessor {
public:
/**
* Constructs a new GlImageCrop Processor
**/
GlImageCrop(IVec2Property* viewportSizeProp);
/**
* Destructor
**/
virtual ~GlImageCrop();
/// \see AbstractProcessor::init
virtual void init();
/// \see AbstractProcessor::deinit
virtual void deinit();
/// \see AbstractProcessor::getName()
virtual const std::string getName() const { return "GlImageCrop"; };
/// \see AbstractProcessor::getDescription()
virtual const std::string getDescription() const { return "Quantizes image intensities into a fixed number of bins using the GPU."; };
/// \see AbstractProcessor::getAuthor()
virtual const std::string getAuthor() const { return "Christian Schulte zu Berge <christian.szb@in.tum.de>"; };
/// \see AbstractProcessor::getProcessorState()
virtual ProcessorState getProcessorState() const { return AbstractProcessor::EXPERIMENTAL; };
DataNameProperty p_inputImage; ///< ID for input volume
DataNameProperty p_outputImage; ///< ID for output gradient volume
IVec3Property p_llf; ///< LLF of cropped region
IVec3Property p_urb; ///< URB of cropped region
protected:
/// \see AbstractProcessor::updateResult
virtual void updateResult(DataContainer& dataContainer);
/// \see AbstractProcessor::updateProperties
virtual void updateProperties(DataContainer& dataContainer);
cgt::Shader* _shader; ///< Shader for resampling
static const std::string loggerCat_;
};
}
#endif // GLIMAGECROP_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