ResInsight/CommonCode/cafEffectGenerator.h
2012-05-18 09:45:23 +02:00

183 lines
6.7 KiB
C++

//##################################################################################################
//
// Custom Visualization Core library
// Copyright (C) 2011-2012 Ceetron AS
//
// This library is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This library is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE.
//
// See the GNU General Public License at <<http://www.gnu.org/licenses/gpl.html>>
// for more details.
//
//##################################################################################################
#pragma once
#include "cvfBase.h"
#include "cvfObject.h"
#include "cvfEffect.h"
#include "cvfScalarMapper.h"
#include "cvfCollection.h"
namespace caf {
//==================================================================================================
//
//
//
//==================================================================================================
class EffectGenerator
{
public:
enum RenderingModeType { FIXED_FUNCTION, SHADER_BASED };
EffectGenerator() {}
virtual ~EffectGenerator() {}
static void setRenderingMode(RenderingModeType effectType);
static RenderingModeType renderingMode();
cvf::ref<cvf::Effect> generateEffect() const;
void updateEffect(cvf::Effect* effect) const;
// Interface that must be implemented in base classes
virtual bool isEqual(const EffectGenerator* other) const = 0;
virtual EffectGenerator* copy() const = 0;
protected:
// When these are called, the effect is already cleared by updateEffect()
virtual void updateForShaderBasedRendering(cvf::Effect* effect) const = 0;
virtual void updateForFixedFunctionRendering(cvf::Effect* effect) const = 0;
private:
static RenderingModeType sm_renderingMode;
};
//==================================================================================================
//
// SurfaceEffectGenerator
//
//==================================================================================================
class SurfaceEffectGenerator : public EffectGenerator
{
public:
SurfaceEffectGenerator(const cvf::Color4f& color, bool polygonOffset);
SurfaceEffectGenerator(const cvf::Color3f& color, bool polygonOffset);
void setCullBackfaces(bool cullBackFaces) { m_cullBackfaces = cullBackFaces; }
virtual bool isEqual(const EffectGenerator* other) const;
virtual EffectGenerator* copy() const;
protected:
virtual void updateForShaderBasedRendering(cvf::Effect* effect) const;
virtual void updateForFixedFunctionRendering(cvf::Effect* effect) const;
private:
void updateCommonEffect(cvf::Effect* effect) const;
private:
cvf::Color4f m_color;
bool m_polygonOffset;
bool m_cullBackfaces;
};
//==================================================================================================
//
// ScalarMapperEffectGenerator
//
//==================================================================================================
class ScalarMapperEffectGenerator : public EffectGenerator
{
public:
ScalarMapperEffectGenerator(const cvf::ScalarMapper* scalarMapper, bool polygonOffset);
void setOpacityLevel(float opacity) { m_opacityLevel = cvf::Math::clamp(opacity, 0.0f , 1.0f ); }
void setUndefinedColor(cvf::Color3f color) { m_undefinedColor = color; }
void setCullBackfaces(bool cullBackFaces) { m_cullBackfaces = cullBackFaces; }
virtual bool isEqual(const EffectGenerator* other) const;
virtual EffectGenerator* copy() const;
public:
static cvf::ref<cvf::TextureImage> addAlphaAndUndefStripes(const cvf::TextureImage* texImg, const cvf::Color3f& undefScalarColor, float opacityLevel);
protected:
virtual void updateForShaderBasedRendering(cvf::Effect* effect) const;
virtual void updateForFixedFunctionRendering(cvf::Effect* effect) const;
private:
void updateCommonEffect(cvf::Effect* effect) const;
private:
cvf::cref<cvf::ScalarMapper> m_scalarMapper;
bool m_polygonOffset;
float m_opacityLevel;
cvf::Color3f m_undefinedColor;
bool m_cullBackfaces;
};
//==================================================================================================
//
// ScalarMapperMeshEffectGenerator
//
//==================================================================================================
class ScalarMapperMeshEffectGenerator : public EffectGenerator
{
public:
ScalarMapperMeshEffectGenerator(const cvf::ScalarMapper* scalarMapper);
void setOpacityLevel(float opacity) { m_opacityLevel = cvf::Math::clamp(opacity, 0.0f , 1.0f ); }
void setUndefinedColor(cvf::Color3f color) { m_undefinedColor = color; }
virtual bool isEqual(const EffectGenerator* other) const;
virtual EffectGenerator* copy() const;
protected:
virtual void updateForShaderBasedRendering(cvf::Effect* effect) const;
virtual void updateForFixedFunctionRendering(cvf::Effect* effect) const;
private:
void updateCommonEffect(cvf::Effect* effect) const;
private:
cvf::cref<cvf::ScalarMapper> m_scalarMapper;
float m_opacityLevel;
cvf::Color3f m_undefinedColor;
};
//==================================================================================================
//
// MeshEffectGenerator
//
//==================================================================================================
class MeshEffectGenerator : public EffectGenerator
{
public:
MeshEffectGenerator(const cvf::Color3f& color);
virtual bool isEqual(const EffectGenerator* other) const;
virtual EffectGenerator* copy() const;
protected:
virtual void updateForShaderBasedRendering(cvf::Effect* effect) const;
virtual void updateForFixedFunctionRendering(cvf::Effect* effect) const;
private:
cvf::Color3f m_color;
};
}