autoevaluationpipeline.cpp 6.77 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, all rights reserved,
schultezub's avatar
schultezub committed
6
//      Christian Schulte zu Berge <christian.szb@in.tum.de>
7
8
9
//      Chair for Computer Aided Medical Procedures
//      Technische Universitt Mnchen
//      Boltzmannstr. 3, 85748 Garching b. Mnchen, Germany
schultezub's avatar
schultezub committed
10
// For a full list of authors and contributors, please refer to the file "AUTHORS.txt".
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
// 
// The licensing of this softare is not yet resolved. Until then, redistribution in source or
// binary forms outside the CAMP chair is not permitted, unless explicitly stated in legal form.
// However, the names of the original authors and the above copyright notice must retain in its
// original state in any case.
// 
// Legal disclaimer provided by the BSD license:
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY 
// AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
// 
// ================================================================================================

30
#include "autoevaluationpipeline.h"
schultezub's avatar
schultezub committed
31
#include "tgt/tgt_gl.h"
schultezub's avatar
schultezub committed
32
#include "tgt/glcanvas.h"
33
#include "tgt/glcontext.h"
34
#include "core/pipeline/visualizationprocessor.h"
35
#include "core/properties/datanameproperty.h"
36
37
#include "core/tools/job.h"
#include "core/tools/opengljobprocessor.h"
38
#include "core/tools/simplejobprocessor.h"
39

40

schultezub's avatar
schultezub committed
41
namespace campvis {
42
    const std::string AutoEvaluationPipeline::loggerCat_ = "CAMPVis.core.datastructures.AutoEvaluationPipeline";
43

44
45
    AutoEvaluationPipeline::AutoEvaluationPipeline(DataContainer* dc) 
        : AbstractPipeline(dc)
46
47
48
    {
    }

49
    AutoEvaluationPipeline::~AutoEvaluationPipeline() {
50
51
    }

52
    void AutoEvaluationPipeline::init() {
53
        AbstractPipeline::init();
schultezub's avatar
schultezub committed
54

55
56
57
        // 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
58
        }
59
60
    }

61
62
63
    void AutoEvaluationPipeline::deinit() {
        for (std::vector<AbstractProcessor*>::iterator it = _processors.begin(); it != _processors.end(); ++it) {
            (*it)->s_invalidated.disconnect(this);
64
        }
65
66
    
        AbstractPipeline::deinit();
67
68
    }

69
    void AutoEvaluationPipeline::onProcessorInvalidated(AbstractProcessor* processor) {
70
71
72
73
74
75
76
77
78
        if (_canvas == 0)
            return;

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

92
    void AutoEvaluationPipeline::addProcessor(AbstractProcessor* processor) {
93
        _isVisProcessorMap.insert(std::make_pair(processor, (dynamic_cast<VisualizationProcessor*>(processor) != 0)));
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109

        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);
                    }
                }
            }
        }

110
111
112
        AbstractPipeline::addProcessor(processor);
    }

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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
    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) {
                it->second->s_changed(it->second);
                ++it;
            }
        }

        AbstractPipeline::onDataContainerDataAdded(name, dh);
    }

152
}