tfgeometry2d.h 4.12 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
25
26
27
28
// 
// ================================================================================================

#ifndef TFGEOMETRY2D_H__
#define TFGEOMETRY2D_H__

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

32
33
#include "core/coreapi.h"

34
namespace cgt {
35
36
37
    class Texture;
}

schultezub's avatar
schultezub committed
38
namespace campvis {
39
40
41
42
43

    /**
     * Defines a single shape for the GeometryTransferFunction class.
     * TFGeometry2D is defined by a sorted list of KeyPoints, each having a position and a color.
     */
44
    class CAMPVIS_CORE_API TFGeometry2D {
45
    public:
46
        struct CAMPVIS_CORE_API KeyPoint {
47
            explicit KeyPoint(const cgt::vec2& position, const cgt::col4& color)
48
49
50
51
                : _position(position)
                , _color(color)
            {};

52
53
            cgt::vec2 _position;
            cgt::col4 _color;
54
55
56
57
58
59
        };

        /**
         * Creates a new TFGeometry2D
         * \param   Bounds  Bounds of the position of the geometry in texture coordinates.
         */
60
        explicit TFGeometry2D(const std::vector<KeyPoint>& keyPoints);
61
62
63
64
65

        /**
         * Virtual destructor
         */
        virtual ~TFGeometry2D();
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.
         */
        TFGeometry2D* clone() const;
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87

        /**
         * Returns the vector of KeyPoints.
         * \return 
         */
        std::vector<KeyPoint>& getKeyPoints();

        /**
         * Renders this transfer function geometry to the current active OpenGL context.
         * \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.
         */
        void render() const;

        /// Signal to be emitted when this TF geometry has changed.
88
        sigslot::signal0 s_changed;
89
90
91
92
93
94
95
96
97

        /**
         * Creates a simple quad geometry for the given interval.
         * A quad geometry consists of two KeyPoints.
         * \param   ll          Lower left corner of the interval
         * \param   ur          Upper right corner of the interval
         * \param   color       Color for geometry
         * \return  A TFGeometry2D modelling a quad with four KeyPoints.
         */
98
        static TFGeometry2D* createQuad(const cgt::vec2& ll, const cgt::vec2& ur, const cgt::col4& color);
99
100
101
102
103
104
105
106
107
108
109
110
111
112
    protected:
        /**
         * Sorts the key points of this TF counter-clockwise.
         * To be called every time the position of one or more KeyPoints changes.
         */
        void computeCenterAndSortKeyPoints();

        std::vector<KeyPoint> _keyPoints;       ///< vector of KeyPoints, KeyPoints are sorted by x-coordinate of the position
        KeyPoint _center;                       ///< the center (position & color) of this geometry
    };

}

#endif // TFGEOMETRY2D_H__