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

autoevaluationpipeline.cpp 6.19 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-2013, 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 Universität München
//      Boltzmannstr. 3, 85748 Garching b. München, 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
#include "autoevaluationpipeline.h"
schultezub's avatar
schultezub committed
26
#include "tgt/tgt_gl.h"
schultezub's avatar
schultezub committed
27
#include "tgt/glcanvas.h"
28
#include "core/pipeline/visualizationprocessor.h"
29
#include "core/properties/datanameproperty.h"
30
31
#include "core/tools/job.h"
#include "core/tools/opengljobprocessor.h"
32
#include "core/tools/simplejobprocessor.h"
33

34

schultezub's avatar
schultezub committed
35
namespace campvis {
36
    const std::string AutoEvaluationPipeline::loggerCat_ = "CAMPVis.core.datastructures.AutoEvaluationPipeline";
37

38
39
    AutoEvaluationPipeline::AutoEvaluationPipeline(DataContainer* dc) 
        : AbstractPipeline(dc)
40
41
42
    {
    }

43
    AutoEvaluationPipeline::~AutoEvaluationPipeline() {
44
45
    }

46
    void AutoEvaluationPipeline::init() {
47
        AbstractPipeline::init();
schultezub's avatar
schultezub committed
48

49
50
51
        // connect invalidation of each processor
        for (std::vector<AbstractProcessor*>::iterator it = _processors.begin(); it != _processors.end(); ++it) {
            (*it)->s_invalidated.connect(this, &AutoEvaluationPipeline::onProcessorInvalidated);
schultezub's avatar
schultezub committed
52
        }
53
54
    }

55
56
57
    void AutoEvaluationPipeline::deinit() {
        for (std::vector<AbstractProcessor*>::iterator it = _processors.begin(); it != _processors.end(); ++it) {
            (*it)->s_invalidated.disconnect(this);
58
        }
59
60
    
        AbstractPipeline::deinit();
61
62
    }

63
    void AutoEvaluationPipeline::onProcessorInvalidated(AbstractProcessor* processor) {
64
        if (_canvas == 0 || _enabled == false)
65
66
67
68
69
70
71
72
            return;

        tbb::concurrent_hash_map<AbstractProcessor*, bool>::const_accessor a;
        if (_isVisProcessorMap.find(a, processor)) {
            if (a->second) {
                // is VisualizationProcessor
                GLJobProc.enqueueJob(
                    _canvas, 
73
                    makeJobOnHeap<AutoEvaluationPipeline, AbstractProcessor*>(this, &AutoEvaluationPipeline::executeProcessorAndCheckOpenGLState, processor), 
74
75
76
                    OpenGLJobProcessor::SerialJob);
            }
            else {
77
                SimpleJobProc.enqueueJob(makeJob<AutoEvaluationPipeline, AbstractProcessor*, bool>(this, &AutoEvaluationPipeline::executeProcessor, processor, false));
78
79
80
81
82
83
84
85
            }
        }
        else {
            tgtAssert(false, "Could not find processor in processor map.");
            LWARNING("Caught invalidation of a non-registered processor!");
        }
    }

86
    void AutoEvaluationPipeline::addProcessor(AbstractProcessor* processor) {
87
        _isVisProcessorMap.insert(std::make_pair(processor, (dynamic_cast<VisualizationProcessor*>(processor) != 0)));
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103

        PropertyCollection pc = processor->getProperties();
        for (size_t i = 0; i < pc.size(); ++i) {
            if (DataNameProperty* dnp = dynamic_cast<DataNameProperty*>(pc[i])) {
                if (dnp->getAccessInfo() == DataNameProperty::READ) {
                    tbb::spin_rw_mutex::scoped_lock lock(_pmMutex, false);
                    std::pair<PortMapType::iterator, bool> result = _portMap.insert(std::make_pair(dnp->getValue(), dnp));
                    tgtAssert(result.second, "Could not insert Property into port map!");
                    if (result.second) {
                        _iteratorMap[dnp] = result.first;
                        dnp->s_changed.connect(this, &AutoEvaluationPipeline::onDataNamePropertyChanged);
                    }
                }
            }
        }

104
105
106
        AbstractPipeline::addProcessor(processor);
    }

107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
    void AutoEvaluationPipeline::onDataNamePropertyChanged(const AbstractProperty* prop) {
        DataNameProperty* dnp = const_cast<DataNameProperty*>(static_cast<const DataNameProperty*>(prop));

        // find string-iterator pair
        IteratorMapType::iterator it = _iteratorMap.find(dnp);
        if (it != _iteratorMap.end()) {
            if (dnp->getValue() != it->second->first) {
                {
                    tbb::spin_rw_mutex::scoped_lock lock(_pmMutex, true);
                    // value of the property has changed
                    _portMap.unsafe_erase(it->second);
                }

                tbb::spin_rw_mutex::scoped_lock lock(_pmMutex, false);
                std::pair<PortMapType::iterator, bool> result = _portMap.insert(std::make_pair(dnp->getValue(), dnp));
                tgtAssert(result.second, "Could not insert Property into port map!");
                if (result.second) {
                    it->second = result.first;
                }
            }
        }
        else {
            tgtAssert(false, "Could not find Property in iterator map!");
        }
    }

    void AutoEvaluationPipeline::onDataContainerDataAdded(const std::string& name, const DataHandle& dh) {
        {
            tbb::spin_rw_mutex::scoped_lock lock(_pmMutex, false);
            PortMapType::const_iterator it = _portMap.find(name);
            while(it != _portMap.end() && it->first == name) {
138
                it->second->setValue(it->second->getValue());
139
140
141
142
143
144
145
                ++it;
            }
        }

        AbstractPipeline::onDataContainerDataAdded(name, dh);
    }

146
}