/***********************************************************************************
 *                                                                                 *
 * Voreen - The Volume Rendering Engine                                            *
 *                                                                                 *
 * Copyright (C) 2005-2012 University of Muenster, Germany.                        *
 * Visualization and Computer Graphics Group <http://viscg.uni-muenster.de>        *
 * For a list of authors please refer to the file "CREDITS.txt".                   *
 *                                                                                 *
 * This file is part of the Voreen software package. Voreen is free software:      *
 * you can redistribute it and/or modify it under the terms of the GNU General     *
 * Public License version 2 as published by the Free Software Foundation.          *
 *                                                                                 *
 * Voreen 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 for more details.      *
 *                                                                                 *
 * You should have received a copy of the GNU General Public License in the file   *
 * "LICENSE.txt" along with this file. If not, see <http://www.gnu.org/licenses/>. *
 *                                                                                 *
 * For non-commercial academic use see the license exception specified in the file *
 * "LICENSE-academic.txt". To get information about commercial licensing please    *
 * contact the authors.                                                            *
 *                                                                                 *
 ***********************************************************************************/

#ifndef VRN_CPURAYCASTER_H
#define VRN_CPURAYCASTER_H

#include "voreen/core/processors/volumeraycaster.h"
#include "voreen/core/properties/transfuncproperty.h"
#include "voreen/core/properties/optionproperty.h"

#include "voreen/core/ports/volumeport.h"

namespace voreen {

/**
 * Performs a simple raycasting on the CPU.
 */
class CPURaycaster : public VolumeRaycaster {
public:
    CPURaycaster();
    virtual Processor* create() const;

    virtual std::string getClassName() const  { return "CPURaycaster"; }
    virtual std::string getCategory() const   { return "Raycasting";   }
    virtual CodeState getCodeState() const    { return CODE_STATE_TESTING; }

    /// All ports except the gradient port need to be connected.
    virtual bool isReady() const;

protected:
    virtual void setDescriptions() {
        setDescription("Performs a simple ray casting on the CPU. Please note: This is more a proof-of-concept than an actually usable processor (very slow!).");
    }

    virtual void process();

    /**
     * Performs the actual ray casting for a single ray,
     * which determined by the passed entry and exit points and the transfer function.
     */
    virtual tgt::vec4 directRendering(const tgt::vec3& first, const tgt::vec3& last, tgt::Texture* tfTexture);
    tgt::vec4 apply1DTF(tgt::Texture* tfTexture, float intensity);
    tgt::vec4 apply2DTF(tgt::Texture* tfTexture, float intensity, float gradientMagnitude);

    VolumePort volumePort_;
    VolumePort gradientVolumePort_;
    RenderPort entryPort_;
    RenderPort exitPort_;
    RenderPort outport_;

    TransFuncProperty transferFunc_;   ///< the property that controls the transfer-function
    IntOptionProperty texFilterMode_;  ///< texture filtering mode to use for volume access

    bool intensityGradientTF_;
};

} // namespace voreen

#endif // VRN_CPURAYCASTER_H
