24.09., 9:00 - 11:00: Due to updates GitLab will be unavailable for some minutes between 09:00 and 11:00.

autoevaluationpipeline.h 5.97 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-2015, 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
    class CAMPVIS_CORE_API AutoEvaluationPipeline : public AbstractPipeline {
43 44
    public:
        /**
45
         * Creates a AutoEvaluationPipeline.
46 47 48 49
         * 
         * \param   dataContainer   Reference to the DataContainer containing local working set of data
         *                          for this pipeline, must be valid the whole lifetime of this pipeline.
         * \param   pipelineName    Name of this pipeline.
50
         */
51
        AutoEvaluationPipeline(DataContainer& dataContainer, const std::string& pipelineName);
52 53 54 55

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


59 60
        /// \see AbstractPipeline::getName()
        virtual std::string getName() const override;
61
        /// \see AbstractPipeline::init()
62
        virtual void init() override;
63
        /// \see AbstractPipeline::deinit()
64
        virtual void deinit() override;
65

66
        /// \see AbstractPipeline::addProcessor()
67
        virtual void addProcessor(AbstractProcessor* processor) override;
schultezub's avatar
schultezub committed
68

69
        /// \see AbstractPipeline::executePipeline()
70
        virtual void executePipeline() override;
71

72 73
    protected:

74 75
        /**
         * Slot getting called when one of the observed processors got invalidated.
76
         * The default behaviour is to dispatch a job to execute the invalidated processor and emit the s_invalidated signal.
77 78 79
         * \param   processor   The processor that emitted the signal
         */
        virtual void onProcessorInvalidated(AbstractProcessor* processor);
80

81 82
        std::string _pipelineName;    ///< Name of this pipeline

83 84 85
        static const std::string loggerCat_;

    private:
86 87 88 89
        /**
         * Callback slot called if one of the DataNameProperties in the port map has changed.
         * \param   prop    DataNameProperty that has changed.
         */
90 91
        void onDataNamePropertyChanged(const AbstractProperty* prop);

92 93 94 95 96 97
        /**
         * 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.
         */
Jakob Weiss's avatar
Jakob Weiss committed
98
        virtual void onDataContainerDataAdded(std::string name, DataHandle dh) override;
99

100 101 102 103 104 105 106 107 108 109 110 111 112 113
        /**
         * Callback when a property was added to one of the PropertyCollections.
         * This property will be added to the port map.
         * \param   property    Property that was added to the collection.
         */
        virtual void onPropertyCollectionPropertyAdded(AbstractProperty* property);

        /**
         * Callback when a property was removed from one of the PropertyCollections.
         * This property will be removed from the port map.
         * \param   property    Property that was added removed from collection.
         */
        virtual void onPropertyCollectionPropertyRemoved(AbstractProperty* property);

114 115 116 117 118 119 120
        /**
         * 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);

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

124
        /// PortMap typedef mapping a string to a set of DataNameProperties using a concurrent unordered multimap
125
        typedef tbb::concurrent_unordered_multimap<std::string, DataNameProperty*> PortMapType;
126
        /// IteratorMap typedef mapping a DataNameProperty to an iterator in a PortMap using a concurrent unordered map
127 128 129 130 131 132
        typedef tbb::concurrent_unordered_map<DataNameProperty*, PortMapType::iterator> IteratorMapType;

        /// Multimap to simulate ports between processors
        PortMapType _portMap;
        IteratorMapType _iteratorMap;
        tbb::spin_rw_mutex _pmMutex;
133 134 135 136
    };

}

137
#endif // AUTOEVALUATIONPIPELINE_H__