tfgeometrymanipulator.h 8.78 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
29
30
31
32
33
34
// ================================================================================================
// 
// 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 Universität München
//      Boltzmannstr. 3, 85748 Garching b. München, 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.
// 
// ================================================================================================

#ifndef TFGEOMETRYMANIPULATOR_H__
#define TFGEOMETRYMANIPULATOR_H__

#include "tgt/vector.h"
#include "tgt/matrix.h"
#include "tgt/event/eventlistener.h"
schultezub's avatar
schultezub committed
35
#include "core/classification/tfgeometry1d.h"
36
#include "core/classification/tfgeometry2d.h"
37
38

namespace TUMVis {
schultezub's avatar
schultezub committed
39
    class Geometry1DTransferFunction;
40
41

    /**
schultezub's avatar
schultezub committed
42
43
44
     * Abstract base class for TFGeometry1D manipulators.
     * TFGeometry1D manipulators encapsulate a TF Geometry (or a part of it) and offer methods
     * for manipulating the TFGeometry1D (which is handy e.g. for TF editors...). Therefore, it
45
46
47
48
49
     * extends the tgt::EventListener class and should implement its methods as necessary.
     */
    class AbstractTFGeometryManipulator : public tgt::EventListener {
    public:
        /**
schultezub's avatar
schultezub committed
50
         * Creates a new AbstractTFGeometryManipulator for the given Geometry1DTransferFunction.
51
52
         * \param   viewportSize    Viewport size (extent of the OpenGL rendering canvas)
         */
53
        AbstractTFGeometryManipulator(const tgt::ivec2& viewportSize);
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86

        /**
         * Pure virtual Destructor
         */
        virtual ~AbstractTFGeometryManipulator() = 0 {};

        /**
         * Sets the new viewport size.
         * \param   viewportSize    The new Viewport size (extent of the OpenGL rendering canvas)
         */
        void setViewportSize(const tgt::ivec2& viewportSize);

        /**
         * Renders the manipulator to the current OpenGL context.
         * \note    Must be called from an active and valid OpenGL context.
         */
        virtual void render() = 0;

    protected:
        /**
         * Transforms TF coordinates to viewport coordinates.
         * \param   pos     Coordinates in TF coordinate system.
         * \return  \a pos converted to viewport coordinates.
         */
        tgt::ivec2 tfToViewport(const tgt::vec2& pos) const;

        /**
         * Transforms viewport coordinates to TF coordinates.
         * \param   pos     Coordnates in viewport coordinate system
         * \return  \a pos converted to TF coordinates
         */
        tgt::vec2 viewportToTF(const tgt::ivec2& pos) const;

schultezub's avatar
schultezub committed
87
        tgt::ivec2 _viewportSize;               ///< Viewport size (extent of the OpenGL rendering canvas)
88
89
90
91
92
    };

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

    /**
schultezub's avatar
schultezub committed
93
     * Class for manipulating the KeyPoints of a TFGeometry1D.
94
95
96
97
98
99
100
101
102
     */
    class KeyPointManipulator : public AbstractTFGeometryManipulator {
    public:
        /**
         * Creates a new KeyPointManipulator
         * \param   viewportSize    Viewport size (extent of the OpenGL rendering canvas)
         * \param   geometry        Parent geometry of the KeyPoint to manipulate
         * \param   keyPoint        Iterator to the KeyPoint to manipulate
         */
103
        KeyPointManipulator(const tgt::ivec2& viewportSize, TFGeometry1D* geometry, const std::vector<TFGeometry1D::KeyPoint>::iterator& keyPoint);
104
105
106
107
108

        /// \see AbstractTFGeometryManipulator::render
        void render();

        /// \see tgt::EventListener::mousePressEvent
109
        virtual void mousePressEvent(tgt::MouseEvent* e);
110
        /// \see tgt::EventListener::mouseReleaseEvent
111
        virtual void mouseReleaseEvent(tgt::MouseEvent* e);
112
        /// \see tgt::EventListener::mouseMoveEvent
113
        virtual void mouseMoveEvent(tgt::MouseEvent* e);
114
115
116
117
        /// \see tgt::EventListener::mouseDoubleClickEvent
        virtual void mouseDoubleClickEvent(tgt::MouseEvent* e);

    protected:
schultezub's avatar
schultezub committed
118
119
120
        static const int MANIPULATOR_SIZE;                          ///< Size of the manipulator
        TFGeometry1D* _geometry;                                    ///< Parent geometry of the KeyPoint to manipulate
        std::vector<TFGeometry1D::KeyPoint>::iterator _keyPoint;    ///< Iterator to the KeyPoint to manipulate
121
122
123

        // event handling stuff:
        bool _mousePressed;                     ///< Flag whether the mouse button is currently pressed
schultezub's avatar
schultezub committed
124
        //TFGeometry1D::KeyPoint _valueWhenPressed; ///< KeyPointValue when pressed
125
126
127
128
129
    };

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

    /**
schultezub's avatar
schultezub committed
130
     * Class for manipulating the whole TFGeometry1D at once.
131
     */
132
    class WholeTFGeometryManipulator : public AbstractTFGeometryManipulator, public sigslot::has_slots<> {
133
134
135
136
137
138
    public:
        /**
         * Creates a new KeyPointManipulator
         * \param   viewportSize    Viewport size (extent of the OpenGL rendering canvas)
         * \param   geometry        Parent geometry of the KeyPoint to manipulate
         */
139
        WholeTFGeometryManipulator(const tgt::ivec2& viewportSize, TFGeometry1D* geometry);
140

141
142
143
144
145
        /**
         * Destructor
         */
        virtual ~WholeTFGeometryManipulator();

146
147
148
149
        /**
         * Returns the Parent geometry of the KeyPoint to manipulate.
         * \return  _geometry
         */
schultezub's avatar
schultezub committed
150
        TFGeometry1D* getGeometry() const;
151

152
153
154
155
156
157
        /**
         * Returns the vector caching the 2D coordinates of the TF key points.
         * \return  _helperPoints
         */
        const std::vector<tgt::vec2>& getHelperPoints() const;

158
159
160
        /// \see AbstractTFGeometryManipulator::render
        void render();

161
162
163
164
165
166
167
168
169
170
171
172
173
174
        /// \see tgt::EventListener::mousePressEvent
        virtual void mousePressEvent(tgt::MouseEvent* e);
        /// \see tgt::EventListener::mouseReleaseEvent
        virtual void mouseReleaseEvent(tgt::MouseEvent* e);
        /// \see tgt::EventListener::mouseMoveEvent
        virtual void mouseMoveEvent(tgt::MouseEvent* e);
        /// \see tgt::EventListener::mouseDoubleClickEvent
        virtual void mouseDoubleClickEvent(tgt::MouseEvent* e);

        /**
         * Slot to be called when the geometry has changed.
         */
        void onGeometryChanged();

175
176
177
        /// Signal to be emitted when the mouse was pressed and has hit this manipulator
        sigslot::signal1<WholeTFGeometryManipulator*> s_selected;

178
    protected:
179
180
181
182
183
184
185
186
187
188
189
190
        /**
         * Checks whether \a position is within the geometry.
         * \param   position    Position to check in TF coordinate system
         * \return  true if \a position is within the bounds of this geometry.
         */
        bool insideGeometry(const tgt::vec2& position) const;

        /**
         * Updates the helper points.
         */
        void updateHelperPoints();

schultezub's avatar
schultezub committed
191
        TFGeometry1D* _geometry;                                ///< Parent geometry of the KeyPoint to manipulate
192
        std::vector<tgt::vec2> _helperPoints;                   ///< vector caching the 2D coordinates of the TF key points
193
194
195
196

        // event handling stuff:
        bool _mousePressed;                                     ///< Flag whether the mouse button is currently pressed
        tgt::vec2 _pressedPosition;                             ///< Position where mousedown occured, in TF coordinates
schultezub's avatar
schultezub committed
197
        std::vector<TFGeometry1D::KeyPoint> _valuesWhenPressed; ///< KeyPoints when pressed
198
199
200
201
202
    };

}

#endif // TFGEOMETRYMANIPULATOR_H__