abstractpipeline.cpp 4.66 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
// ================================================================================================
// 
// This file is part of the TUMVis Visualization Framework.
// 
// If not explicitly stated otherwise: Copyright (C) 2012, all rights reserved,
//      Christian Schulte zu Berge (christian.szb@in.tum.de)
//      Chair for Computer Aided Medical Procedures
//      Technische Universitt Mnchen
//      Boltzmannstr. 3, 85748 Garching b. Mnchen, Germany
// 
// 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.
// 
// ================================================================================================

29
#include "abstractpipeline.h"
schultezub's avatar
schultezub committed
30

schultezub's avatar
schultezub committed
31
#include "tgt/exception.h"
schultezub's avatar
schultezub committed
32
#include "core/pipeline/abstractprocessor.h"
33
34
#include <ctime>

35
36
37
38

namespace TUMVis {
    const std::string AbstractPipeline::loggerCat_ = "TUMVis.core.datastructures.AbstractPipeline";

39
    AbstractPipeline::AbstractPipeline() 
40
        : HasPropertyCollection()
41
        , _enabled(true)
schultezub's avatar
   
schultezub committed
42
43
44
45
46
47
    {
    }

    AbstractPipeline::~AbstractPipeline() {
    }

48
    void AbstractPipeline::init() {
schultezub's avatar
schultezub committed
49
50
        initAllProperties();

51
        // initialize all processors:
schultezub's avatar
schultezub committed
52
53
54
55
56
57
58
59
        for (std::vector<AbstractProcessor*>::iterator it = _processors.begin(); it != _processors.end(); ++it) {
            try {
                (*it)->init();
            }
            catch (tgt::Exception& e) {
                LERROR("Caught Exception during initialization of processor: " << e.what());
            }
        }
60
    }
schultezub's avatar
schultezub committed
61

62
    void AbstractPipeline::deinit() {
schultezub's avatar
schultezub committed
63
64
        deinitAllProperties();

65
66
67
68
69
70
71
72
73
74
75
        // deinitialize all processors:
        for (std::vector<AbstractProcessor*>::iterator it = _processors.begin(); it != _processors.end(); ++it) {
            try {
                (*it)->deinit();
            }
            catch (tgt::Exception& e) {
                LERROR("Caught Exception during deinitialization of processor: " << e.what());
            }
        }
    }

schultezub's avatar
schultezub committed
76
77
78
79
80
    void AbstractPipeline::onPropertyChanged(const AbstractProperty* prop) {
        _invalidationLevel.setLevel(InvalidationLevel::INVALID_RESULT);
        s_PipelineInvalidated();
    }

81
    void AbstractPipeline::onProcessorInvalidated(AbstractProcessor* processor) {
82
        _invalidationLevel.setLevel(InvalidationLevel::INVALID_RESULT);
83
        s_PipelineInvalidated();
schultezub's avatar
schultezub committed
84
85
86
87
88
89
    }

    const DataContainer& AbstractPipeline::getDataContainer() const {
        return _data;
    }

90
91
92
93
    DataContainer& AbstractPipeline::getDataContainer() {
        return _data;
    }

94
95
96
    void AbstractPipeline::executeProcessor(AbstractProcessor* processor) {
        tgtAssert(processor != 0, "Processor must not be 0.");

97
        if (processor->getEnabled() && !processor->getInvalidationLevel().isValid()) {
98
            processor->lockProperties();
99
100
101
#ifdef TUMVIS_DEBUG
            clock_t startTime = clock();
#endif
102
            processor->process(_data);
103
104
105
#ifdef TUMVIS_DEBUG
            clock_t endTime = clock();
#endif
106
            processor->unlockProperties();
107
108
109
110

#ifdef TUMVIS_DEBUG
            LDEBUG("Executed processor " << processor->getName() << " duration: " << (endTime - startTime));
#endif
111
        }
112
113
114
115
116
117
    }

    InvalidationLevel& AbstractPipeline::getInvalidationLevel() {
        return _invalidationLevel;
    }

118
119
120
121
    const std::vector<AbstractProcessor*>& AbstractPipeline::getProcessors() const {
        return _processors;
    }

122
123
124
125
126
127
128
129
    bool AbstractPipeline::getEnabled() const {
        return _enabled;
    }

    void AbstractPipeline::setEnabled(bool enabled) {
        _enabled = enabled;
    }

130
}