abstractprocessor.h 5.06 KB
Newer Older
schultezub's avatar
schultezub committed
1
2
3
4
#ifndef PROCESSOR_H__
#define PROCESSOR_H__

#include "tgt/logmanager.h"
schultezub's avatar
schultezub committed
5
#include "core/tools/invalidationlevel.h"
schultezub's avatar
schultezub committed
6
#include "core/datastructures/datacontainer.h"
schultezub's avatar
schultezub committed
7
8
9
10
11
#include "core/properties/abstractproperty.h"
#include "core/properties/propertycollection.h"

#include <string>
#include <vector>
schultezub's avatar
schultezub committed
12
13

namespace TUMVis {
schultezub's avatar
schultezub committed
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
    class AbstractProcessor;

    /**
     * Observer Arguments for Property observers.
     */
    struct ProcessorObserverArgs : public GenericObserverArgs<AbstractProcessor> {
        /**
         * Creates new PropertyObserverArgs.
         * \param subject               Subject that emits the notification
         * \param invalidationLevel     Invalidation level of that property
         */
        ProcessorObserverArgs(const AbstractProcessor* subject, InvalidationLevel invalidationLevel)
            : GenericObserverArgs<AbstractProcessor>(subject)
            , _invalidationLevel(invalidationLevel)
        {}

        InvalidationLevel _invalidationLevel;       ///< Invalidation level of that processor
    };

schultezub's avatar
schultezub committed
33
34
35

    /**
     * Abstract base class for TUMVis Processors.
36
37
38
39
40
41
42
43
     * 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
44
45
46
     * 
     * \sa AbstractPipeline
     */
schultezub's avatar
schultezub committed
47
    class AbstractProcessor : public GenericObserver<PropertyObserverArgs>, public GenericObservable<ProcessorObserverArgs> {
48
49
50
51
52
53
54
55
56
57

    /**
     * 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.
     */
    friend class AbstractPipeline;

schultezub's avatar
schultezub committed
58
    public:
59

schultezub's avatar
schultezub committed
60
61
62
63
64
65
66
67
68
69
70
        /**
         * Creates a AbstractProcessor.
         */
        AbstractProcessor();

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


schultezub's avatar
schultezub committed
71
        /**
72
73
74
         * Initializes the processor.
         * Everything that requires a valid OpenGL context or is otherwise expensive gets in here.
         * 
schultezub's avatar
schultezub committed
75
76
77
         * \note    When overwriting this method, make sure to call the base class version first.
         */
        virtual void init();
78
79
80
81
82
83
        
        /**
         * Deinitializes this processors.
         * \note    When overwriting this method, make sure to call the base class version first.
         */
        virtual void deinit();
schultezub's avatar
schultezub committed
84

schultezub's avatar
schultezub committed
85
86
        /**
         * Execute this processor.
87
         * \param data      DataContainer to work on.
schultezub's avatar
schultezub committed
88
         **/
89
        virtual void process(DataContainer& data) = 0;
schultezub's avatar
schultezub committed
90

91
92
        /**
         * Returns the invalidation level of this processor.
schultezub's avatar
schultezub committed
93
         * \return _invalidationLevel
94
         */
schultezub's avatar
schultezub committed
95
        const InvalidationLevel& getInvalidationLevel() const;
96
97

        /**
schultezub's avatar
schultezub committed
98
         * Returns the PropertyCollection of this processor.
99
         * \return  _properties
100
         */
schultezub's avatar
schultezub committed
101
102
103
104
105
106
107
108
        PropertyCollection& getPropertyCollection();

        /**
         * Update the processor's invalidation level by \a nl.
         * If \a nl is VALID, the processor's invalidation level will be set to VALID.
         * If \a nl is one of the INVALID_X state, the processor's corresponding flag will be set.
         * \param nl    Invalidation level to apply.
         */
109
110
        void applyInvalidationLevel(InvalidationLevel il);
        
schultezub's avatar
schultezub committed
111
112
113
114
115
116
117
        /**
         * Gets called when one of the observed properties changed notifies its observers.
         * \sa GenericObserver::onNotify, AbstractProperty
         * \param poa   PropertyObserverArgs    ObserverArgument struct containing the emitting property and its InvalidationLevel
         */
        virtual void onNotify(const PropertyObserverArgs& poa);

118
119
120
121
122
123
124
125
126
127
128
129
        /**
         * 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();

130

schultezub's avatar
schultezub committed
131
    protected:
schultezub's avatar
schultezub committed
132
133
134
135
        InvalidationLevel _invalidationLevel;       ///< current invalidation level of this processor

        PropertyCollection _properties;             ///< PropertyCollection of this processor

schultezub's avatar
schultezub committed
136
137
138
139
140
141
142

        static const std::string loggerCat_;
    };

}

#endif // PROCESSOR_H__