tfgeometry1d.h 6.73 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-2014, 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
// 
// ================================================================================================

schultezub's avatar
schultezub committed
25
26
#ifndef TFGEOMETRY1D_H__
#define TFGEOMETRY1D_H__
27

28
#include "sigslot/sigslot.h"
29
30
31
#include "tgt/vector.h"
#include <vector>

32
33
#include "core/coreapi.h"

34
35
36
37
namespace tgt {
    class Texture;
}

schultezub's avatar
schultezub committed
38
namespace campvis {
39
    class FaceGeometry;
40
41
42

    /**
     * Defines a single shape for the GeometryTransferFunction class.
schultezub's avatar
schultezub committed
43
     * TFGeometry1D is defined by a sorted list of KeyPoints, each having a position and a color.
44
     */
45
    class CAMPVIS_CORE_API TFGeometry1D {
46
    public:
47
        struct CAMPVIS_CORE_API KeyPoint {
48
            explicit KeyPoint(float position, const tgt::col4& color)
49
50
51
52
53
54
55
56
57
                : _position(position)
                , _color(color)
            {};

            float _position;
            tgt::col4 _color;
        };

        /**
schultezub's avatar
schultezub committed
58
         * Creates a new TFGeometry1D
59
60
         * \param   Bounds  Bounds of the position of the geometry in texture coordinates.
         */
61
        explicit TFGeometry1D(const std::vector<KeyPoint>& keyPoints);
62
63
64
65

        /**
         * Virtual destructor
         */
schultezub's avatar
schultezub committed
66
        virtual ~TFGeometry1D();
67

68
69
70
71
72
73
        /**
         * Clones this transfer function geometry.
         * \return  A clone of this transfer function geometry, caller takes ownership of the pointer.
         */
        TFGeometry1D* clone() const;

74
75
76
77
78
        /**
         * Returns the vector of KeyPoints.
         * \return 
         */
        std::vector<KeyPoint>& getKeyPoints();
79
        
80
        /**
81
82
83
84
         * Renders this transfer function geometry to the current active OpenGL context for usage in editor.
         * \note    Must be called from an active and valid OpenGL context.
         * \todo    Check, whether this method really belongs here (core) or better fits into
         *          an other class in the application (GUI) module.
85
         */
86
        void renderIntoEditor() const;
87

88
89
90
        /**
         * Renders this transfer function geometry to the current active OpenGL context.
         * \note    Must be called from an active and valid OpenGL context.
91
92
         * \todo    Check, whether this method really belongs here (core) or better fits into
         *          an other class in the application (GUI) module.
93
94
95
         */
        void render() const;

96
        /// Signal to be emitted when this TF geometry has changed.
97
        sigslot::signal0 s_changed;
98

99
100
101
        /**
         * Creates a simple quad geometry for the given interval.
         * A quad geometry consists of two KeyPoints.
102
         * \param   interval    Interval the geometry resides in, must be in [0, 1].
103
104
         * \param   leftColor   Color for left KeyPoint
         * \param   rightColor  Color for right KeyPoint
schultezub's avatar
schultezub committed
105
         * \return  A TFGeometry1D modelling a quad with two KeyPoints.
106
         */
107
        static TFGeometry1D* createQuad(const tgt::vec2& interval, const tgt::col4& leftColor, const tgt::col4& rightColor);
108
109
110
111
112
113
114
115
116
        
        /**
         * Creates a ramp geometry for the given interval.
         * A quad geometry consists of two KeyPoints, the left one having 0 opacity, the right one with full opacity.
         * \param   interval    Interval the geometry resides in, must be in [0, 1].
         * \param   color       Color for ramp
         * \return  A TFGeometry1D modelling a ramp with two KeyPoints.
         */
        static TFGeometry1D* crateRamp(const tgt::vec2& interval, const tgt::col4& color);
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140

        /**
         * Creates a diverging color map of two diverging colors blending over white.
         * \param   interval    Interval the geometry resides in, must be in [0, 1].
         * \param   leftColor   Color for left diverging color.
         * \param   rightColor  Color for right diverging color
         * \return  A TFGeometry1D modelling a diverging color map with three key points.
         */
        static TFGeometry1D* createDivergingColorMap(const tgt::vec2& interval, const tgt::col4& leftColor, const tgt::col4& rightColor, float bias = 0.5f);

        /**
         * Creates the cold-hot color map blending blue to red via white.
         * \param   interval    Intensity domain for color map, must be in [0, 1].
         * \return  A TFGeometry1D building the cold-hot color map for the given interval.
         */
        static TFGeometry1D* createColdHotColorMap(const tgt::vec2& interval = tgt::vec2(0.f, 1.f));

        /**
         * Creates the heated body color map blending black-red-yellow-white.
         * \param   interval    Intensity domain for color map, must be in [0, 1].
         * \return  A TFGeometry1D building the heated body color map for the given interval.
         */
        static TFGeometry1D* createHeatedBodyColorMap(const tgt::vec2& interval = tgt::vec2(0.f, 1.f));

141
142
143
    protected:

        std::vector<KeyPoint> _keyPoints;       ///< vector of KeyPoints, KeyPoints are sorted by x-coordinate of the position
144
145
        FaceGeometry* _tfRenderFace;            ///< FaceGeometry used to render TF into the TF texture
        FaceGeometry* _tfEditorFace;            ///< FaceGeometry used to render TF into editor window
146
147
148
149
150
151
152
153
154
155
    };

// ================================================================================================

    /**
     * Less operator for sorting KeyPoints by their position.
     * \param   left    Left KeyPoint to compare
     * \param   right   RightKeyPoint to compare
     * \return  left._position < right._position
     */
156
    CAMPVIS_CORE_API bool operator< (const TFGeometry1D::KeyPoint& left, const TFGeometry1D::KeyPoint& right);
157
158
159

}

schultezub's avatar
schultezub committed
160
#endif // TFGEOMETRY1D_H__