abstractprocessor.h 6.8 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.
// 
// ================================================================================================

schultezub's avatar
schultezub committed
30
31
32
#ifndef PROCESSOR_H__
#define PROCESSOR_H__

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

#include <string>
#include <vector>
schultezub's avatar
schultezub committed
41

schultezub's avatar
schultezub committed
42
namespace campvis {
schultezub's avatar
schultezub committed
43
44
    class AbstractProperty;

schultezub's avatar
schultezub committed
45
    /**
schultezub's avatar
schultezub committed
46
     * Abstract base class for CAMPVis Processors.
47
48
49
50
51
52
53
54
     * A processor implements a specific task, which it performs on the DataCollection passed
     * during process(). Properties provide a transparent layer for adjusting the processor's 
     * behaviour.
     * Once a processor has finished it sets it should set its invalidation level to valid. As
     * soon as one of its properties changes, the processor will be notified and possibliy
     * change its invalidation level. Observing pipelines will be notified of this and can
     * and have to decide which part of the pipeline has to be re-evaluated wrt. the processor's
     * invalidation level.
schultezub's avatar
schultezub committed
55
56
57
     * 
     * \sa AbstractPipeline
     */
schultezub's avatar
schultezub committed
58
    class AbstractProcessor : public HasPropertyCollection {
59
60
61
62
63
64
65
66

    /**
     * We have to find a trade-off:
     * On the one hand, we want to follow the information-hiding concept and keep the processor's
     * properties private. On the other hand pipelines will usually want direct access to them
     * (e.g. in order to setup data IDs or property sharing) and the properties in the PropertyCollection
     * are not strongly typed. Hence, we declare AbstractPipeline as our friend.
     */
schultezub's avatar
schultezub committed
67
    friend class AbstractPipeline;  // TODO: this does not work as intended...
68

schultezub's avatar
schultezub committed
69
    public:
70

schultezub's avatar
schultezub committed
71
72
73
74
75
76
77
78
79
80
81
        /**
         * Creates a AbstractProcessor.
         */
        AbstractProcessor();

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


schultezub's avatar
schultezub committed
82
        /**
83
84
85
         * Initializes the processor.
         * Everything that requires a valid OpenGL context or is otherwise expensive gets in here.
         * 
schultezub's avatar
schultezub committed
86
87
88
         * \note    When overwriting this method, make sure to call the base class version first.
         */
        virtual void init();
89
90
        
        /**
schultezub's avatar
schultezub committed
91
         * Deinitializes this processor.
92
         * \note    When overwriting this method, make sure to call the base class version at the end.
93
94
         */
        virtual void deinit();
schultezub's avatar
schultezub committed
95

schultezub's avatar
schultezub committed
96
97
        /**
         * Execute this processor.
98
         * \param data      DataContainer to work on.
schultezub's avatar
schultezub committed
99
         **/
100
        virtual void process(DataContainer& data) = 0;
schultezub's avatar
schultezub committed
101

102
103
        /**
         * Returns the invalidation level of this processor.
schultezub's avatar
schultezub committed
104
         * \return _invalidationLevel
105
         */
schultezub's avatar
schultezub committed
106
        const InvalidationLevel& getInvalidationLevel() const;
107

108
109
110
111
112
113
        /**
         * Gets the name of this very processor. To be defined by every subclass.
         * \return  The name of this processor.
         */
        virtual const std::string getName() const = 0;

114
115
116
117
118
119
        /**
         * Gets a description of this processor. To be defined by every subclass.
         * \return  A description what this processor does.
         */
        virtual const std::string getDescription() const = 0;

schultezub's avatar
schultezub committed
120
        /**
schultezub's avatar
schultezub committed
121
122
123
124
         * Update the processor's invalidation level by \a il.
         * If \a il is VALID, the processor's invalidation level will be set to VALID.
         * If \a il is one of the INVALID_X state, the processor's corresponding flag will be set.
         * \param il    Invalidation level to apply.
schultezub's avatar
schultezub committed
125
         */
126
        void applyInvalidationLevel(InvalidationLevel il);
127
128
129
130
131
132
133
134
135
136
137
138

        /**
         * Gets the flag whether this processor is currently enabled.
         * \return _enabled
         */
        bool getEnabled() const;

        /**
         * Sets the flag whether this processor is currently enabled.
         * \param   enabled     New flag whether this processor is currently enabled.
         */
        void setEnabled(bool enabled);
139
        
140
141
142
143
144
145
146
147
148
149
150
151
        /**
         * Locks all properties in the processor's PropertyCollection and marks them as "in use".
         * \sa  AbstractProcessor::unlock
         */
        void lockProperties();

        /**
         * Unlocks all properties in the processor's PropertyCollection and marks them as "not in use".
         * \sa  AbstractProcessor::lock
         */
        void unlockProperties();

152

schultezub's avatar
schultezub committed
153
        /// Signal emitted when the processor has been invalidated.
154
        sigslot::signal1<AbstractProcessor*> s_invalidated;
schultezub's avatar
schultezub committed
155
156
157
158
159
160
161
162

        /**
         * Slot getting called when one of the observed properties changed and notifies its observers.
         * \param   prop    Property that emitted the signal
         */
        virtual void onPropertyChanged(const AbstractProperty* prop);


schultezub's avatar
schultezub committed
163
    protected:
schultezub's avatar
schultezub committed
164
        InvalidationLevel _invalidationLevel;       ///< current invalidation level of this processor
165
        bool _enabled;                              ///< flag whether this processor is currently enabled
schultezub's avatar
schultezub committed
166

schultezub's avatar
schultezub committed
167
168
169
170
171
172
        static const std::string loggerCat_;
    };

}

#endif // PROCESSOR_H__