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

Merge branch 'lightsourcedata' into 'development'

Lightsourcedata
parents 7cfd88e4 d6fec679
......@@ -31,6 +31,7 @@
#include "application/gui/qtdatahandle.h"
#include "core/datastructures/datacontainer.h"
#include "core/datastructures/abstractdata.h"
#include "core/datastructures/lightsourcedata.h"
#include "core/datastructures/facegeometry.h"
#include "core/datastructures/meshgeometry.h"
#include "core/datastructures/indexedmeshgeometry.h"
......@@ -132,6 +133,10 @@ namespace campvis {
else if (const ImageSeries* tester = dynamic_cast<const ImageSeries*>(data)) {
return QVariant(QString("Image Series"));
}
else if (const LightSourceData* tester = dynamic_cast<const LightSourceData*>(data)) {
return QVariant(QString("Light Source"));
}
}
else
return QVariant();
......
// ================================================================================================
//
// This file is part of the CAMPVis Software Framework.
//
// If not explicitly stated otherwise: Copyright (C) 2012-2013, all rights reserved,
// Christian Schulte zu Berge <christian.szb@in.tum.de>
// Chair for Computer Aided Medical Procedures
// Technische Universität München
// Boltzmannstr. 3, 85748 Garching b. München, 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 PROCESSORDECORATORSHADING_H__
#define PROCESSORDECORATORSHADING_H__
#include "tgt/textureunit.h"
#include "core/pipeline/processordecoratorgradient.h"
#include "core/properties/floatingpointproperty.h"
#include "core/properties/genericproperty.h"
#include "core/properties/optionproperty.h"
namespace campvis {
class CAMPVIS_CORE_API ProcessorDecoratorShading : public ProcessorDecoratorGradient {
public:
explicit ProcessorDecoratorShading(const std::string& lightUniformName = "_lightSource");
virtual ~ProcessorDecoratorShading();
protected:
void addProperties(AbstractProcessor* propCollection);
void renderProlog(const DataContainer& dataContainer, tgt::Shader* shader);
std::string generateHeader() const;
BoolProperty _enableShading; ///< Flag whether to enable shading;
Vec3Property _lightPosition; ///< Light position
Vec3Property _ambientColor; ///< Ambient light color
Vec3Property _diffuseColor; ///< Diffuse light color
Vec3Property _specularColor; ///< Specular light color
FloatProperty _shininess; ///< Specular shininess
Vec3Property _attenuation; ///< Attenuation factors
const std::string _lightUniformName; ///< Uniform name for light
};
}
#endif // PROCESSORDECORATORSHADING_H__
// ================================================================================================
//
// This file is part of the CAMPVis Software Framework.
//
// If not explicitly stated otherwise: Copyright (C) 2012-2013, all rights reserved,
// Christian Schulte zu Berge <christian.szb@in.tum.de>
// Chair for Computer Aided Medical Procedures
// Technische Universität München
// Boltzmannstr. 3, 85748 Garching b. München, 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 "lightsourcedata.h"
#include "tgt/shadermanager.h"
namespace campvis {
LightSourceData::LightSourceData(const tgt::vec3& lightPosition, const tgt::vec3& ambientColor /*= tgt::vec3(.4f)*/, const tgt::vec3& diffuseColor /*= tgt::vec3(.75f)*/, const tgt::vec3& specularColor /*= tgt::vec3(.6f)*/, float shininess /*= 24.f*/, const tgt::vec3& attenuation /*= tgt::vec3(0.f)*/)
: AbstractData()
, _lightPosition(lightPosition)
, _ambientColor(ambientColor)
, _diffuseColor(diffuseColor)
, _specularColor(specularColor)
, _shininess(shininess)
, _attenuation(attenuation)
{
}
LightSourceData::~LightSourceData() {
}
LightSourceData* LightSourceData::clone() const {
return new LightSourceData(*this);
}
size_t LightSourceData::getLocalMemoryFootprint() const {
return sizeof(LightSourceData);
}
size_t LightSourceData::getVideoMemoryFootprint() const {
return 0;
}
void LightSourceData::bind(tgt::Shader* shader, const std::string& uniformName) const {
tgt::Shader::IgnoreUniformLocationErrorGuard guard(shader);
shader->setUniform(uniformName + "._position", _lightPosition);
shader->setUniform(uniformName + "._ambientColor", _ambientColor);
shader->setUniform(uniformName + "._diffuseColor", _diffuseColor);
shader->setUniform(uniformName + "._specularColor", _specularColor);
shader->setUniform(uniformName + "._shininess", _shininess);
shader->setUniform(uniformName + "._attenuation", _attenuation);
}
}
\ No newline at end of file
// ================================================================================================
//
// This file is part of the CAMPVis Software Framework.
//
// If not explicitly stated otherwise: Copyright (C) 2012, all rights reserved,
// Christian Schulte zu Berge <christian.szb@in.tum.de>
// Chair for Computer Aided Medical Procedures
// Technische Universität München
// Boltzmannstr. 3, 85748 Garching b. München, Germany
// For a full list of authors and contributors, please refer to the file "AUTHORS.txt".
//
// The licensing of this softare is not yet resolved. Until then, redistribution in source or
// binary forms outside the CAMP chair is not permitted, unless explicitly stated in legal form.
// However, the names of the original authors and the above copyright notice must retain in its
// original state in any case.
//
// Legal disclaimer provided by the BSD license:
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
// AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
// ================================================================================================
#ifndef LIGHTSOURCEDATA_H__
#define LIGHTSOURCEDATA_H__
#include "tgt/vector.h"
#include "core/datastructures/abstractdata.h"
namespace tgt {
class Shader;
}
namespace campvis {
/**
* Abstract base class for data handled by a DataHandle and stored in a DataContainer.
*
* \todo
*/
class CAMPVIS_CORE_API LightSourceData : public AbstractData {
public:
/**
* Constructor, Creates a new light source.
* \param lightPosition The light position
* \param ambientColor The ambient color
* \param diffuseColor The diffuse color
* \param specularColor The specular color
* \param shininess The shininess
* \param attenuation The attenuation factors
*/
explicit LightSourceData(
const tgt::vec3& lightPosition,
const tgt::vec3& ambientColor = tgt::vec3(.4f),
const tgt::vec3& diffuseColor = tgt::vec3(.75f),
const tgt::vec3& specularColor = tgt::vec3(.6f),
float shininess = 24.f,
const tgt::vec3& attenuation = tgt::vec3(0.f));
/**
* Virtual destructor
*/
virtual ~LightSourceData();
/// \see AbstractData::clone()
virtual LightSourceData* clone() const;
/// \see AbstractData::getLocalMemoryFootprint()
virtual size_t getLocalMemoryFootprint() const;
/// \see AbstractData::getVideoMemoryFootprint()
virtual size_t getVideoMemoryFootprint() const;
/**
* Binds this light source to the given shader by setting the corresponding uniforms.
* \param shader Shader to bind to.
* \param uniformName Uniform name to use.
*/
void bind(tgt::Shader* shader, const std::string& uniformName) const;
/**
* Gets the light positoin.
* \return _lightPosition
**/
tgt::vec3 getLightPosition() const { return _lightPosition; }
/**
* Sets the light positoin.
* \param _lightPosition New value for the light positoin.
**/
void setLightPosition(tgt::vec3 val) { _lightPosition = val; }
/**
* Gets the ambient color.
* \return _ambientColor
**/
tgt::vec3 getAmbientColor() const { return _ambientColor; }
/**
* Sets the ambient color.
* \param _ambientColor New value for the ambient color.
**/
void setAmbientColor(tgt::vec3 val) { _ambientColor = val; }
/**
* Gets the diffuse light color.
* \return _diffuseColor
**/
tgt::vec3 getDiffuseColor() const { return _diffuseColor; }
/**
* Sets the diffuse light color.
* \param _diffuseColor New value for the diffuse light color.
**/
void setDiffuseColor(tgt::vec3 val) { _diffuseColor = val; }
/**
* Gets the specular color.
* \return _specularColor
**/
tgt::vec3 getSpecularColor() const { return _specularColor; }
/**
* Sets the specular color.
* \param _specularColor New value for the specular color.
**/
void setSpecularColor(tgt::vec3 val) { _specularColor = val; }
/**
* Gets the specular shininess.
* \return _shininess
**/
float getShininess() const { return _shininess; }
/**
* Sets the specular shininess.
* \param _shininess New value for the specular shininess.
**/
void setShininess(float val) { _shininess = val; }
/**
* Gets the attenuation factors.
* \return _attenuation
**/
tgt::vec3 getAttenuation() const { return _attenuation; }
/**
* Sets the attenuation factors.
* \param _attenuation New value for the attenuation factors.
**/
void setAttenuation(tgt::vec3 val) { _attenuation = val; }
protected:
tgt::vec3 _lightPosition; ///< Light position
tgt::vec3 _ambientColor; ///< Ambient light color
tgt::vec3 _diffuseColor; ///< Diffuse light color
tgt::vec3 _specularColor; ///< Specular light color
float _shininess; ///< Specular shininess
tgt::vec3 _attenuation; ///< Attenuation factors
};
}
#endif // LIGHTSOURCEDATA_H__
\ No newline at end of file
......@@ -42,6 +42,7 @@ namespace campvis {
PredicateDemoAchilles::PredicateDemoAchilles(DataContainer* dc)
: AutoEvaluationPipeline(dc)
, _lsp()
, _imageReader()
, _labelReader()
, _confidenceReader()
......@@ -50,6 +51,7 @@ namespace campvis {
, _snrFilter(&_canvasSize)
, _ve(&_canvasSize)
{
addProcessor(&_lsp);
addProcessor(&_imageReader);
addProcessor(&_labelReader);
addProcessor(&_confidenceReader);
......
......@@ -33,6 +33,7 @@
#include "core/pipeline/autoevaluationpipeline.h"
#include "core/properties/cameraproperty.h"
#include "modules/base/processors/lightsourceprovider.h"
#include "modules/io/processors/mhdimagereader.h"
#include "modules/advancedusvis/processors/pointpredicateevaluator.h"
#include "modules/advancedusvis/processors/predicatevolumeexplorer.h"
......@@ -81,6 +82,7 @@ namespace campvis {
*/
virtual void onProcessorValidated(AbstractProcessor* processor);
LightSourceProvider _lsp;
MhdImageReader _imageReader;
MhdImageReader _labelReader;
MhdImageReader _confidenceReader;
......
......@@ -42,6 +42,7 @@ namespace campvis {
PredicateDemoCarotid::PredicateDemoCarotid(DataContainer* dc)
: AutoEvaluationPipeline(dc)
, _lsp()
, _imageReader()
, _labelReader()
, _confidenceReader()
......@@ -51,6 +52,7 @@ namespace campvis {
, _snrFilter(&_canvasSize)
, _ve(&_canvasSize)
{
addProcessor(&_lsp);
addProcessor(&_imageReader);
addProcessor(&_labelReader);
addProcessor(&_confidenceReader);
......
......@@ -34,6 +34,7 @@
#include "core/pipeline/autoevaluationpipeline.h"
#include "core/properties/cameraproperty.h"
#include "modules/base/processors/lightsourceprovider.h"
#include "modules/io/processors/mhdimagereader.h"
#include "modules/advancedusvis/processors/pointpredicateevaluator.h"
#include "modules/advancedusvis/processors/predicatevolumeexplorer.h"
......@@ -82,6 +83,7 @@ namespace campvis {
*/
virtual void onProcessorValidated(AbstractProcessor* processor);
LightSourceProvider _lsp;
MhdImageReader _imageReader;
MhdImageReader _labelReader;
MhdImageReader _confidenceReader;
......
......@@ -42,6 +42,7 @@ namespace campvis {
PredicateDemoCarotid2::PredicateDemoCarotid2(DataContainer* dc)
: AutoEvaluationPipeline(dc)
, _lsp()
, _imageReader()
, _labelReader()
, _confidenceReader()
......@@ -51,6 +52,7 @@ namespace campvis {
, _snrFilter(&_canvasSize)
, _ve(&_canvasSize)
{
addProcessor(&_lsp);
addProcessor(&_imageReader);
addProcessor(&_labelReader);
addProcessor(&_confidenceReader);
......
......@@ -34,6 +34,7 @@
#include "core/pipeline/autoevaluationpipeline.h"
#include "core/properties/cameraproperty.h"
#include "modules/base/processors/lightsourceprovider.h"
#include "modules/io/processors/mhdimagereader.h"
#include "modules/advancedusvis/processors/pointpredicateevaluator.h"
#include "modules/advancedusvis/processors/predicatevolumeexplorer.h"
......@@ -82,6 +83,7 @@ namespace campvis {
*/
virtual void onProcessorValidated(AbstractProcessor* processor);
LightSourceProvider _lsp;
MhdImageReader _imageReader;
MhdImageReader _labelReader;
MhdImageReader _confidenceReader;
......
......@@ -42,6 +42,7 @@ namespace campvis {
PredicateDemoShoulder::PredicateDemoShoulder(DataContainer* dc)
: AutoEvaluationPipeline(dc)
, _lsp()
, _imageReader()
, _labelReader()
, _confidenceReader()
......@@ -50,6 +51,7 @@ namespace campvis {
, _snrFilter(&_canvasSize)
, _ve(&_canvasSize)
{
addProcessor(&_lsp);
addProcessor(&_imageReader);
addProcessor(&_labelReader);
addProcessor(&_confidenceReader);
......
......@@ -33,6 +33,7 @@
#include "core/pipeline/autoevaluationpipeline.h"
#include "core/properties/cameraproperty.h"
#include "modules/base/processors/lightsourceprovider.h"
#include "modules/io/processors/mhdimagereader.h"
#include "modules/advancedusvis/processors/pointpredicateevaluator.h"
#include "modules/advancedusvis/processors/predicatevolumeexplorer.h"
......@@ -81,6 +82,7 @@ namespace campvis {
*/
virtual void onProcessorValidated(AbstractProcessor* processor);
LightSourceProvider _lsp;
MhdImageReader _imageReader;
MhdImageReader _labelReader;
MhdImageReader _confidenceReader;
......
......@@ -27,8 +27,9 @@
#include "tgt/textureunit.h"
#include "core/tools/quadrenderer.h"
#include "core/datastructures/lightsourcedata.h"
#include "core/datastructures/renderdata.h"
#include "core/pipeline/processordecoratorshading.h"
#include "core/pipeline/processordecoratorgradient.h"
namespace campvis {
const std::string PointPredicateRaycaster::loggerCat_ = "CAMPVis.modules.vis.PointPredicateRaycaster";
......@@ -39,14 +40,19 @@ namespace campvis {
, p_inputSnr("InputSnr", "Input SNR", "", DataNameProperty::READ)
, p_inputVesselness("InputVesselness", "Input Vesselness", "", DataNameProperty::READ)
, p_inputConfidence("InputConfidence", "Input Confidence", "", DataNameProperty::READ)
, p_enableShading("EnableShading", "Enable Shading", true)
, p_lightId("LightId", "Input Light Source", "lightsource", DataNameProperty::READ)
, p_predicateHistogram("PredicateSelection", "Voxel Predicate Selection")
{
addDecorator(new ProcessorDecoratorShading());
addDecorator(new ProcessorDecoratorGradient());
addProperty(p_inputLabels, INVALID_RESULT | INVALID_PROPERTIES);
addProperty(p_inputSnr);
addProperty(p_inputVesselness);
addProperty(p_inputConfidence);
addProperty(p_enableShading, INVALID_RESULT | INVALID_PROPERTIES | INVALID_SHADER);
addProperty(p_lightId);
addProperty(p_predicateHistogram);
decoratePropertyCollection(this);
......@@ -72,53 +78,64 @@ namespace campvis {
ImageRepresentationGL::ScopedRepresentation confidence(dataContainer, p_inputConfidence.getValue());
if (labels && snr && vesselness && confidence) {
const tgt::Texture* lt = labels->getTexture();
if (lt->getFilter() != tgt::Texture::NEAREST) {
const_cast<tgt::Texture*>(lt)->setFilter(tgt::Texture::NEAREST);
}
const tgt::Texture* tex = image->getTexture();
if (tex->getFilter() != tgt::Texture::MIPMAP) {
const_cast<tgt::Texture*>(tex)->setFilter(tgt::Texture::MIPMAP);
LGL_ERROR;
glGenerateMipmap(GL_TEXTURE_3D);
ScopedTypedData<LightSourceData> light(dataContainer, p_lightId.getValue());
if (p_enableShading.getValue() == false || light != nullptr) {
const tgt::Texture* lt = labels->getTexture();
if (lt->getFilter() != tgt::Texture::NEAREST) {
const_cast<tgt::Texture*>(lt)->setFilter(tgt::Texture::NEAREST);
}
const tgt::Texture* tex = image->getTexture();
if (tex->getFilter() != tgt::Texture::MIPMAP) {
const_cast<tgt::Texture*>(tex)->setFilter(tgt::Texture::MIPMAP);
LGL_ERROR;
glGenerateMipmap(GL_TEXTURE_3D);
LGL_ERROR;
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
LGL_ERROR;
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
LGL_ERROR;
}
tgt::TextureUnit labelUnit, snrUnit, vesselnessUnit, confidenceUnit;
labels->bind(_shader, labelUnit, "_labels", "_labelsParams");
snr->bind(_shader, snrUnit, "_snr", "_snrParams");
vesselness->bind(_shader, vesselnessUnit, "_vesselness", "_vesselnessParams");
confidence->bind(_shader, confidenceUnit, "_confidence", "_confidenceParams");
if (p_enableShading.getValue() && light != nullptr) {
light->bind(_shader, "_lightSource");
}
_shader->setIgnoreUniformLocationError(true);
p_predicateHistogram.getPredicateHistogram()->setupRenderShader(_shader);
_shader->setIgnoreUniformLocationError(false);
LGL_ERROR;
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
LGL_ERROR;
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
LGL_ERROR;
}
tgt::TextureUnit labelUnit, snrUnit, vesselnessUnit, confidenceUnit;
labels->bind(_shader, labelUnit, "_labels", "_labelsParams");
snr->bind(_shader, snrUnit, "_snr", "_snrParams");
vesselness->bind(_shader, vesselnessUnit, "_vesselness", "_vesselnessParams");
confidence->bind(_shader, confidenceUnit, "_confidence", "_confidenceParams");
FramebufferActivationGuard fag(this);
createAndAttachTexture(GL_RGBA8);
createAndAttachTexture(GL_RGBA32F);
createAndAttachTexture(GL_RGBA32F);
createAndAttachDepthTexture();
_shader->setIgnoreUniformLocationError(true);
p_predicateHistogram.getPredicateHistogram()->setupRenderShader(_shader);
_shader->setIgnoreUniformLocationError(false);
LGL_ERROR;
static const GLenum buffers[] = { GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1 , GL_COLOR_ATTACHMENT2 };
glDrawBuffers(3, buffers);
FramebufferActivationGuard fag(this);
createAndAttachTexture(GL_RGBA8);
createAndAttachTexture(GL_RGBA32F);
createAndAttachTexture(GL_RGBA32F);
createAndAttachDepthTexture();
glEnable(GL_DEPTH_TEST);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
QuadRdr.renderQuad();
static const GLenum buffers[] = { GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1 , GL_COLOR_ATTACHMENT2 };
glDrawBuffers(3, buffers);
glEnable(GL_DEPTH_TEST);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
QuadRdr.renderQuad();
// restore state
glDrawBuffers(1, buffers);
glDisable(GL_DEPTH_TEST);
LGL_ERROR;
// restore state
glDrawBuffers(1, buffers);
glDisable(GL_DEPTH_TEST);
LGL_ERROR;
dataContainer.addData(p_targetImageID.getValue(), new RenderData(_fbo));
dataContainer.addData(p_targetImageID.getValue(), new RenderData(_fbo));
}
else {
LDEBUG("Could not load light source from DataContainer.");
}
}
else {
LERROR("Could not load Voxel Predicate Mask Image.");
......@@ -127,6 +144,8 @@ namespace campvis {
std::string PointPredicateRaycaster::generateHeader() const {
std::string toReturn = RaycastingProcessor::generateHeader();
if (p_enableShading.getValue())
toReturn += "#define ENABLE_SHADING\n";
toReturn += p_predicateHistogram.getPredicateHistogram()->getGlslHeader();
return toReturn;
......@@ -136,4 +155,10 @@ namespace campvis {
invalidate(INVALID_SHADER);
}
void PointPredicateRaycaster::updateProperties(DataContainer& dataContainer) {
p_lightId.setVisible(p_enableShading.getValue());
RaycastingProcessor::updateProperties(dataContainer);