abstractprocessor.h 4.15 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 : 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
71
72
        /**
         * Creates a AbstractProcessor.
         */
        AbstractProcessor();

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


        /**
         * Execute this processor.
73
         * \param data      DataContainer to work on.
schultezub's avatar
schultezub committed
74
         **/
75
        virtual void process(DataContainer& data) = 0;
schultezub's avatar
schultezub committed
76

77
78
        /**
         * Returns the invalidation level of this processor.
schultezub's avatar
schultezub committed
79
         * \return _invalidationLevel
80
         */
schultezub's avatar
schultezub committed
81
        const InvalidationLevel& getInvalidationLevel() const;
82
83

        /**
schultezub's avatar
schultezub committed
84
         * Returns the PropertyCollection of this processor.
85
         * \return  _properties
86
         */
schultezub's avatar
schultezub committed
87
88
89
90
91
92
93
94
        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.
         */
95
96
        void applyInvalidationLevel(InvalidationLevel il);
        
schultezub's avatar
schultezub committed
97
98
99
100
101
102
103
        /**
         * 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);

104

schultezub's avatar
schultezub committed
105
    protected:
schultezub's avatar
schultezub committed
106
107
108
109
        InvalidationLevel _invalidationLevel;       ///< current invalidation level of this processor

        PropertyCollection _properties;             ///< PropertyCollection of this processor

schultezub's avatar
schultezub committed
110
111
112
113
114
115
116

        static const std::string loggerCat_;
    };

}

#endif // PROCESSOR_H__