raycastingprocessor.h 6.76 KB
Newer Older
1
2
// ================================================================================================
// 
schultezub's avatar
schultezub committed
3
// This file is part of the CAMPVis Software Framework.
4
// 
5
// If not explicitly stated otherwise: Copyright (C) 2012-2013, all rights reserved,
schultezub's avatar
schultezub committed
6
//      Christian Schulte zu Berge <christian.szb@in.tum.de>
7
//      Chair for Computer Aided Medical Procedures
8
9
//      Technische Universität München
//      Boltzmannstr. 3, 85748 Garching b. München, Germany
10
// 
schultezub's avatar
schultezub committed
11
// For a full list of authors and contributors, please refer to the file "AUTHORS.txt".
12
// 
13
14
15
16
// 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
17
// 
18
19
20
21
// 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.
22
23
24
// 
// ================================================================================================

25
26
27
28
29
30
#ifndef RAYCASTINGPROCESSOR_H__
#define RAYCASTINGPROCESSOR_H__

#include <string>

#include "core/pipeline/visualizationprocessor.h"
31
#include "core/pipeline/abstractprocessordecorator.h"
32
#include "core/properties/cameraproperty.h"
schultezub's avatar
schultezub committed
33
#include "core/properties/datanameproperty.h"
34
#include "core/properties/genericproperty.h"
35
#include "core/properties/floatingpointproperty.h"
36
37
#include "core/properties/transferfunctionproperty.h"

38
39
#include "core/datastructures/imagerepresentationgl.h"

40
41
42
43
namespace tgt {
    class Shader;
}

schultezub's avatar
schultezub committed
44
namespace campvis {
45
46
47
48
49
50
51
52
53
54
    /**
     * Base class for raycasting processors.
     * Offfers properties various common properties and automatic shader loading/linking.
     *
     * \note    The intended way to use this class is to inherit from it, add additional properties if necessary
     *          and implement the processImpl() method which will be called by RaycastingProcessor::process()
     *          after successful validation of the incoming images.
     *          Of course you can also directly overwrite process() yourself, but then you will need to to the
     *          sanity checks yourself.
     */
55
    class RaycastingProcessor : public VisualizationProcessor, public HasProcessorDecorators {
56
57
58
59
60
61
    public:
        /**
         * Creates a RaycastingProcessor.
         * \note    The render target size property of this RaycastingProcessor will automatically 
         *          be assigned as shared property of the given \a renderTargetSize property.
         * \see     VisualizationProcessor
62
         * \param   viewportSizeProp            Pointer to the parent pipeline's render target size property.
63
64
65
         * \param   fragmentShaderFileName      Filename for the fragment shader being automatically loaded.
         * \param   bindEntryExitDepthTextures  Flag whether to also bind the depth textures of the entry-/exit points.
         */
66
        RaycastingProcessor(IVec2Property* viewportSizeProp, const std::string& fragmentShaderFileName, bool bindEntryExitDepthTextures);
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97

        /**
         * Destructor
         **/
        virtual ~RaycastingProcessor();

        /**
         * Initalizes the Processor, loads and builds the shader.
         * \see     AbstractProcessor::init
         * \note    When overwriting this method, make sure to call the base class version first.
         */
        virtual void init();

        /**
         * Disposes the shader and deinitializes the processor.
         * \see     AbstractProcessor::deinit
         * \note    When overwriting this method, make sure to call the base class version at the end.
         */
        virtual void deinit();

        /**
         * Performs sanity checks, sets up the rendering and calls RaycastingProcessor::processImpl().
         * This method first reads the input image, entry and exit points from \a data and validates them. On sucess
         * the shader will be rebuild if necessary, the shader will be activated, common uniforms will be set and
         * the textures and transfer function will be bound before calling processImpl().
         *
         * \sa      RaycastingProcessor::processImpl()
         * \param   data    DataContainer to work on.
         */
        virtual void process(DataContainer& data);

98
99
100
        /// \see    AbstractProcessor::updateProperties
        virtual void updateProperties(DataContainer& dc);

101
102
103
        DataNameProperty p_sourceImageID;                ///< image ID for input image
        DataNameProperty p_entryImageID;                 ///< image ID for output entry points image
        DataNameProperty p_exitImageID;                  ///< image ID for output exit points image
104

105
106
107
        CameraProperty p_camera;                         ///< Camera used for ray casting
        TransferFunctionProperty p_transferFunction;     ///< Transfer function
        FloatProperty p_jitterStepSizeMultiplier;        ///< Step size multiplier for entry points jitter
108
        FloatProperty p_samplingRate;                    ///< Ray casting sampling rate
109
110
111
112
113
114
115
116
117

    protected:
        /**
         * Gets called by RaycastingProcessor::process().
         * Put additional (processor specific) setup code here, create and activate your render target(s), render
         * your quad and store your results in \a data.
         *
         * \sa      RaycastingProcessor::process()
         * \param   data    DataContainer to work on.
118
         * \param   image   The image to render
119
         */
120
        virtual void processImpl(DataContainer& data, ImageRepresentationGL::ScopedRepresentation& image) = 0;
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135

        /**
         * Returns an additional header that will be linked into the fragment shader.
         * Gets calles when building \a _shader. Overwrite this method to add a processor specific header to
         * your fragment shader.
         * \note    When overwriting this method make sure to call the base class version and append its result.
         * \return  The current default implementation returns an empty string.
         */
        virtual std::string generateHeader() const;

        const std::string _fragmentShaderFilename;      ///< Filename for the fragment shader being automatically loaded.
        tgt::Shader* _shader;                           ///< Shader for raycasting
        bool _bindEntryExitDepthTextures;               ///< Flag whether to also bind the depth textures of the entry-/exit points.

        static const std::string loggerCat_;
136
137
138

    private:
        clock_t _sourceImageTimestamp;
139
140
141
142
143
    };

}

#endif // RAYCASTINGPROCESSOR_H__