autoevaluationpipeline.h 4.9 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-2014, 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 Universitaet Muenchen
//      Boltzmannstr. 3, 85748 Garching b. Muenchen, 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
#ifndef AUTOEVALUATIONPIPELINE_H__
#define AUTOEVALUATIONPIPELINE_H__
27

schultezub's avatar
schultezub committed
28
#include "sigslot/sigslot.h"
29
30
31
#include <tbb/concurrent_hash_map.h>
#include <tbb/concurrent_unordered_map.h>
#include <tbb/spin_rw_mutex.h>
32

33
34
#include "core/pipeline/abstractpipeline.h"

schultezub's avatar
schultezub committed
35

schultezub's avatar
schultezub committed
36
namespace campvis {
37
    /**
38
39
40
     * Specializtaion of AbstractPipeline performing automatic execution of invalidated processors.
     * AutoEvaluationPipeline connects to the s_(in)validated signals of all of its processors and
     * executes processors with invalid results using the correct threads.
41
42
43
     * 
     * \param   dc  Pointer to the DataContainer containing local working set of data for this 
     *              pipeline, must not be 0, must be valid the whole lifetime of this pipeline.
44
     */
45
    class CAMPVIS_CORE_API AutoEvaluationPipeline : public AbstractPipeline {
46
47
    public:
        /**
48
         * Creates a AutoEvaluationPipeline.
49
         */
50
        AutoEvaluationPipeline(DataContainer* dc);
51
52
53
54

        /**
         * Virtual Destructor
         **/
55
        virtual ~AutoEvaluationPipeline();
56
57


58
        /// \see AbstractPipeline::init()
59
        virtual void init();
60
        /// \see AbstractPipeline::deinit()
61
62
        virtual void deinit();

63
64
        /// \see AbstractPipeline::addProcessor()
        virtual void addProcessor(AbstractProcessor* processor);
schultezub's avatar
schultezub committed
65
66

    protected:
67
68
        /**
         * Slot getting called when one of the observed processors got invalidated.
69
         * The default behaviour is to dispatch a job to execute the invalidated processor and emit the s_invalidated signal.
70
71
72
         * \param   processor   The processor that emitted the signal
         */
        virtual void onProcessorInvalidated(AbstractProcessor* processor);
73

74
75
76
        static const std::string loggerCat_;

    private:
77
78
79
80
        /**
         * Callback slot called if one of the DataNameProperties in the port map has changed.
         * \param   prop    DataNameProperty that has changed.
         */
81
82
        void onDataNamePropertyChanged(const AbstractProperty* prop);

83
84
85
86
87
88
        /**
         * Gets called when the data collection of this pipeline has changed and thus has notified its observers.
         * If \a name equals the name of the renderTarget, the s_renderTargetChanged signal will be emitted.
         * \param   name    Name of the added data.
         * \param   dh      DataHandle to the newly added data.
         */
89
90
        virtual void onDataContainerDataAdded(const std::string& name, const DataHandle& dh);

91
92
93
94
95
96
97
        /**
         * Recursively looks for all DataNameProperties in \a pc and adds them to the port map.
         * If \a pc contains a MetaProperty, it will be seached recursively.
         * \param   pc  PropertyCollection to search for DataNameProperties.
         */
        void findDataNamePropertiesAndAddToPortMap(const HasPropertyCollection* pc);

98
        /// Hashmap storing for each processor whether it's a VisualizationProcessor or not.
99
100
        tbb::concurrent_hash_map<AbstractProcessor*, bool> _isVisProcessorMap;

101
        /// PortMap typedef mapping a string to a set of DataNameProperties using a concurrent unordered multimap
102
        typedef tbb::concurrent_unordered_multimap<std::string, DataNameProperty*> PortMapType;
103
        /// IteratorMap typedef mapping a DataNameProperty to an iterator in a PortMap using a concurrent unordered map
104
105
106
107
108
109
        typedef tbb::concurrent_unordered_map<DataNameProperty*, PortMapType::iterator> IteratorMapType;

        /// Multimap to simulate ports between processors
        PortMapType _portMap;
        IteratorMapType _iteratorMap;
        tbb::spin_rw_mutex _pmMutex;
110
111
112
113
    };

}

114
#endif // AUTOEVALUATIONPIPELINE_H__