tfgeometry1d.h 6.65 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
26
#ifndef TFGEOMETRY1D_H__
#define TFGEOMETRY1D_H__
27

28
#include "sigslot/sigslot.h"
29
30
31
32
33
34
35
#include "tgt/vector.h"
#include <vector>

namespace tgt {
    class Texture;
}

schultezub's avatar
schultezub committed
36
namespace campvis {
37
    class FaceGeometry;
38
39
40

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

            float _position;
            tgt::col4 _color;
        };

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

        /**
         * Virtual destructor
         */
schultezub's avatar
schultezub committed
64
        virtual ~TFGeometry1D();
65

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

72
73
74
75
76
        /**
         * Returns the vector of KeyPoints.
         * \return 
         */
        std::vector<KeyPoint>& getKeyPoints();
77
        
78
        /**
79
80
81
82
         * 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.
83
         */
84
        void renderIntoEditor() const;
85

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

94
95
96
        /// Signal to be emitted when this TF geometry has changed.
        sigslot::signal0<> s_changed;

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

        /**
         * 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));

139
140
141
    protected:

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

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

    /**
     * Less operator for sorting KeyPoints by their position.
     * \param   left    Left KeyPoint to compare
     * \param   right   RightKeyPoint to compare
     * \return  left._position < right._position
     */
schultezub's avatar
schultezub committed
154
    bool operator< (const TFGeometry1D::KeyPoint& left, const TFGeometry1D::KeyPoint& right);
155
156
157

}

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