tfgeometrymanipulator.h 8.51 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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
// ================================================================================================
// 
// 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"
#include "core/classification/tfgeometry.h"

namespace TUMVis {
    class GeometryTransferFunction;

    /**
     * Abstract base class for TFGeometry manipulators.
     * TFGeometry manipulators encapsulate a TF Geometry (or a part of it) and offer methods
     * for manipulating the TFGeometry (which is handy e.g. for TF editors...). Therefore, it
     * extends the tgt::EventListener class and should implement its methods as necessary.
     */
    class AbstractTFGeometryManipulator : public tgt::EventListener {
    public:
        /**
         * Creates a new AbstractTFGeometryManipulator for the given GeometryTransferFunction.
         * \param   viewportSize    Viewport size (extent of the OpenGL rendering canvas)
         * \param   tf              Parent TF of the geometries to manipulate
         */
        AbstractTFGeometryManipulator(const tgt::ivec2& viewportSize, GeometryTransferFunction* tf);

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

        tgt::ivec2 _viewportSize;           ///< Viewport size (extent of the OpenGL rendering canvas)
        GeometryTransferFunction* _tf;      ///< Parent TF of the geometries to manipulate (might be handy somewhere later...)
    };

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

    /**
     * Class for manipulating the KeyPoints of a TFGeometry.
     */
    class KeyPointManipulator : public AbstractTFGeometryManipulator {
    public:
        /**
         * Creates a new KeyPointManipulator
         * \param   viewportSize    Viewport size (extent of the OpenGL rendering canvas)
         * \param   tf              Parent TF of the geometries to manipulate
         * \param   geometry        Parent geometry of the KeyPoint to manipulate
         * \param   keyPoint        Iterator to the KeyPoint to manipulate
         */
        KeyPointManipulator(const tgt::ivec2& viewportSize, GeometryTransferFunction* tf, TFGeometry* geometry, const std::vector<TFGeometry::KeyPoint>::iterator& keyPoint);

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

        /// \see tgt::EventListener::mousePressEvent
111
        virtual void mousePressEvent(tgt::MouseEvent* e);
112
        /// \see tgt::EventListener::mouseReleaseEvent
113
        virtual void mouseReleaseEvent(tgt::MouseEvent* e);
114
        /// \see tgt::EventListener::mouseMoveEvent
115
        virtual void mouseMoveEvent(tgt::MouseEvent* e);
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
        /// \see tgt::EventListener::mouseDoubleClickEvent
        virtual void mouseDoubleClickEvent(tgt::MouseEvent* e);

    protected:
        static const int MANIPULATOR_SIZE;                      ///< Size of the manipulator
        TFGeometry* _geometry;                                  ///< Parent geometry of the KeyPoint to manipulate
        std::vector<TFGeometry::KeyPoint>::iterator _keyPoint;  ///< Iterator to the KeyPoint to manipulate

        // event handling stuff:
        bool _mousePressed;                     ///< Flag whether the mouse button is currently pressed
        //TFGeometry::KeyPoint _valueWhenPressed; ///< KeyPointValue when pressed
    };

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

    /**
     * Class for manipulating the whole TFGeometry at once.
     */
134
    class WholeTFGeometryManipulator : public AbstractTFGeometryManipulator, public sigslot::has_slots<> {
135
136
137
138
139
140
141
142
143
    public:
        /**
         * Creates a new KeyPointManipulator
         * \param   viewportSize    Viewport size (extent of the OpenGL rendering canvas)
         * \param   tf              Parent TF of the geometries to manipulate
         * \param   geometry        Parent geometry of the KeyPoint to manipulate
         */
        WholeTFGeometryManipulator(const tgt::ivec2& viewportSize, GeometryTransferFunction* tf, TFGeometry* geometry);

144
145
146
147
148
        /**
         * Destructor
         */
        virtual ~WholeTFGeometryManipulator();

149
150
151
        /// \see AbstractTFGeometryManipulator::render
        void render();

152
153
154
155
156
157
158
159
160
161
162
163
164
165
        /// \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();

166
    protected:
167
168
169
170
171
172
173
174
175
176
177
178
        /**
         * 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();

179
        TFGeometry* _geometry;          ///< Parent geometry of the KeyPoint to manipulate
180
181
182
183
184
185
        std::vector<tgt::vec2> _helperPoints;

        // event handling stuff:
        bool _mousePressed;                                     ///< Flag whether the mouse button is currently pressed
        tgt::vec2 _pressedPosition;                             ///< Position where mousedown occured, in TF coordinates
        std::vector<TFGeometry::KeyPoint> _valuesWhenPressed;   ///< KeyPoints when pressed
186
187
188
189
190
    };

}

#endif // TFGEOMETRYMANIPULATOR_H__