abstractpipeline.h 6.58 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, all rights reserved,
schultezub's avatar
schultezub committed
6
//      Christian Schulte zu Berge <christian.szb@in.tum.de>
7
8
9
//      Chair for Computer Aided Medical Procedures
//      Technische Universität München
//      Boltzmannstr. 3, 85748 Garching b. München, Germany
schultezub's avatar
schultezub committed
10
// For a full list of authors and contributors, please refer to the file "AUTHORS.txt".
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
// 
// 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.
// 
// ================================================================================================

30
31
32
#ifndef ABSTRACTPIPELINE_H__
#define ABSTRACTPIPELINE_H__

33
#include "sigslot/sigslot.h"
34
#include "tgt/logmanager.h"
schultezub's avatar
schultezub committed
35
#include "tbb/include/tbb/spin_mutex.h"
36
#include "tbb/include/tbb/mutex.h"
schultezub's avatar
schultezub committed
37
#include "core/tools/invalidationlevel.h"
38
#include "core/datastructures/datacontainer.h"
schultezub's avatar
schultezub committed
39
#include "core/properties/propertycollection.h"
40
41
42

#include <vector>

schultezub's avatar
schultezub committed
43
namespace campvis {
schultezub's avatar
schultezub committed
44
    class AbstractProcessor;
45
    class PipelineEvaluator;
schultezub's avatar
schultezub committed
46

47
    /**
schultezub's avatar
schultezub committed
48
     * Abstract base class for CAMPVis Pipelines.
49
50
     * 
     */
schultezub's avatar
schultezub committed
51
    class AbstractPipeline : public HasPropertyCollection {
52
53
    friend class PipelineEvaluator;

54
55
56
57
    public:
        /**
         * Creates a AbstractPipeline.
         */
58
        AbstractPipeline();
59
60
61
62
63
64
65
66

        /**
         * Virtual Destructor
         **/
        virtual ~AbstractPipeline();


        /**
67
68
         * Initializes this pipeline and all of its processors.
         * Everything that requires a valid OpenGL context or is otherwise expensive gets in here.
69
70
         * 
         * \note    When overwriting this method, make sure to call the base class version first.
71
         */
72
        virtual void init();
73

74
75
76
77
78
79
        /**
         * Deinitializes this pipeline and all of its processors.
         * \note    When overwriting this method, make sure to call the base class version first.
         */
        virtual void deinit();

80
        /**
81
82
83
         * Execute this pipeline.
         **/
        virtual void execute() = 0;
84

schultezub's avatar
schultezub committed
85
        /**
86
         * Returns the DataContainer of this pipeline, const version.
schultezub's avatar
schultezub committed
87
88
89
         * \return _data
         */
        const DataContainer& getDataContainer() const;
90

91
92
93
94
95
96
        /**
         * Returns the DataContainer of this pipeline, non-const version.
         * \return _data
         */
        DataContainer& getDataContainer();

97
98
99
100
101
102
        /**
         * Adds the processors \a processor to this pipeline's processor list.
         * \param   processor   The processor to add.
         */
        void addProcessor(AbstractProcessor* processor);

103
104
105
106
107
108
109
110
111
112
113
        /**
         * Returns the list of processors of this pipeline.
         * \return  _processors
         */
        const std::vector<AbstractProcessor*>& getProcessors() const;

        /**
         * Gets the name of this very pipeline. To be defined by every subclass.
         * \return  The name of this pipeline.
         */
        virtual const std::string getName() const = 0;
schultezub's avatar
schultezub committed
114
        
schultezub's avatar
schultezub committed
115
116
117
118
        /**
         * Gets the current InvalidationLevel of this pipeline.
         * \return _invalidationLevel
         */
119
120
        InvalidationLevel& getInvalidationLevel();

121
122
123
124
125
126
127
128
129
130
131
132
        /**
         * Gets the flag whether this pipeline is currently enabled.
         * \return _enabled
         */
        bool getEnabled() const;

        /**
         * Sets the flag whether this pipeline is currently enabled.
         * \param   enabled     New flag whether this pipeline is currently enabled.
         */
        void setEnabled(bool enabled);

schultezub's avatar
schultezub committed
133
        /// Signal being emitted when this pipeline has been invalidated.
134
135
        sigslot::signal0<> s_PipelineInvalidated;

schultezub's avatar
schultezub committed
136
    protected:
schultezub's avatar
schultezub committed
137
138
139
140
141
142
143
144
145
146
147
148
        /**
         * Slot getting called when one of the observed properties changed and notifies its observers.
         * The default behaviour is just to set the invalidation level to invalid.
         * \param   prop    Property that emitted the signal
         */
        virtual void onPropertyChanged(const AbstractProperty* prop);

        /**
         * Slot getting called when one of the observed processors got invalidated.
         * The default behaviour is just to set the invalidation level to invalid.
         * \param   processor   The processor that emitted the signal
         */
149
        virtual void onProcessorInvalidated(AbstractProcessor* processor);
schultezub's avatar
schultezub committed
150

151
152
153
154
        /**
         * Executes the processor \a processor on the pipeline's data and locks its properties meanwhile.
         * \param   processor   Processor to execute.
         */
155
        void executeProcessor(AbstractProcessor* processor);
156
157


158
159
        DataContainer _data;                                ///< DataContainer containing local working set of data for this Pipeline

160
        std::vector<AbstractProcessor*> _processors;        ///< List of all processors of this pipeline
schultezub's avatar
schultezub committed
161
        InvalidationLevel _invalidationLevel;               ///< current invalidation level
162
        bool _enabled;                                      ///< flag whether this pipeline is currently enabled
schultezub's avatar
schultezub committed
163
164

        tbb::spin_mutex _localMutex;                        ///< mutex for altering local members
165
        tbb::mutex _evaluationMutex;                        ///< mutex for the evaluation of this pipeline
166
167
168
169
170
171
172
173

        static const std::string loggerCat_;
    };

}


#endif // ABSTRACTPIPELINE_H__