transferfunctionproperty.cpp 4.53 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
// 
// ================================================================================================

schultezub's avatar
schultezub committed
25
#include "transferfunctionproperty.h"
26
27
#include "core/datastructures/imagedata.h"
#include "core/datastructures/imagerepresentationlocal.h"
28

schultezub's avatar
schultezub committed
29
namespace campvis {
30

schultezub's avatar
schultezub committed
31
    const std::string TransferFunctionProperty::loggerCat_ = "CAMPVis.core.datastructures.TransferFunctionProperty";
32

33
34
    TransferFunctionProperty::TransferFunctionProperty(const std::string& name, const std::string& title, AbstractTransferFunction* tf, int invalidationLevel /*= AbstractProcessor::INVALID_RESULT*/)
        : AbstractProperty(name, title, invalidationLevel)
35
        , _transferFunction(tf)
36
37
        , _imageHandle(0)
        , _autoFitWindowToData(true)
38
39
    {
        tgtAssert(tf != 0, "Assigned transfer function must not be 0.");
schultezub's avatar
schultezub committed
40
        tf->s_changed.connect(this, &TransferFunctionProperty::onTFChanged);
41
42
43
    }

    TransferFunctionProperty::~TransferFunctionProperty() {
schultezub's avatar
schultezub committed
44
45
        _transferFunction->s_changed.disconnect(this);
        delete _transferFunction;
46
47
48
49
50
51
52
    }

    AbstractTransferFunction* TransferFunctionProperty::getTF() {
        return _transferFunction;
    }

    void TransferFunctionProperty::onTFChanged() {
schultezub's avatar
schultezub committed
53
        s_changed(this);
54
55
    }

schultezub's avatar
schultezub committed
56
57
    void TransferFunctionProperty::deinit() {
        _transferFunction->deinit();
58
        _imageHandle = DataHandle(0);
schultezub's avatar
schultezub committed
59
60
    }

61
62
63
    void TransferFunctionProperty::replaceTF(AbstractTransferFunction* tf) {
        tgtAssert(tf != 0, "Transfer function must not be 0.");
        s_BeforeTFReplace(_transferFunction);
64

65
        if (_transferFunction != 0) {
66
            _transferFunction->s_changed.disconnect(this);
67
68
            _transferFunction->deinit();
        }
69
        delete _transferFunction;
70
71


72
        _transferFunction = tf;
73
74
75
        if (_transferFunction != 0)
            _transferFunction->s_changed.connect(this, &TransferFunctionProperty::onTFChanged);

76
77
78
        s_AfterTFReplace(_transferFunction);
    }

79
80
81
82
    void TransferFunctionProperty::addSharedProperty(AbstractProperty* prop) {
        tgtAssert(false, "Sharing of TF properties not supported!");
    }

83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
    campvis::DataHandle TransferFunctionProperty::getImageHandle() const {
        return _imageHandle;
    }

    void TransferFunctionProperty::setImageHandle(DataHandle imageHandle) {
        tgtAssert(
            imageHandle.getData() == 0 || dynamic_cast<const ImageData*>(imageHandle.getData()) != 0, 
            "The data in the image handle must either be 0 or point to a valid ImageData object!");

        if (_autoFitWindowToData && imageHandle.getData() != 0) {
            if (const ImageData* id = dynamic_cast<const ImageData*>(imageHandle.getData())) {
            	const ImageRepresentationLocal* localRep = id->getRepresentation<ImageRepresentationLocal>();
                if (localRep != 0) {
                    const Interval<float>& ii = localRep->getNormalizedIntensityRange();
                    _transferFunction->setIntensityDomain(tgt::vec2(ii.getLeft(), ii.getRight()));
                }
            }
        }

        _imageHandle = imageHandle;
        s_imageHandleChanged();
    }

    void TransferFunctionProperty::setAutoFitWindowToData(bool newValue) {
        _autoFitWindowToData = newValue;
        s_autoFitWindowToDataChanged();
    }

    bool TransferFunctionProperty::getAutoFitWindowToData() const {
        return _autoFitWindowToData;
    }

115
}