datacontainerinspectorcanvas.h 8.53 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, 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
schultezub's avatar
schultezub committed
10
// For a full list of authors and contributors, please refer to the file "AUTHORS.txt".
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// 
// 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 DATACONTAINERINSPECTORCANVAS_H__
#define DATACONTAINERINSPECTORCANVAS_H__

#include "sigslot/sigslot.h"
#include "tgt/painter.h"
35
36
#include "tgt/event/eventlistener.h"
#include "tgt/event/mouseevent.h"
37
38
#include "tgt/qt/qtcontextmanager.h"
#include "tgt/qt/qtthreadedcanvas.h"
schultezub's avatar
schultezub committed
39
#include "tbb/mutex.h"
40

41
42
43
44
45
#include "application/gui/qtdatahandle.h"

#include "core/properties/propertycollection.h"
#include "core/properties/numericproperty.h"
#include "core/properties/transferfunctionproperty.h"
46
#include "core/tools/opengljobprocessor.h"
47
#include "modules/vis/processors/geometryrenderer.h"
48
49
50
51

namespace tgt {
    class Shader;
    class Texture;
52
    class TextureUnit;
53
54
}

schultezub's avatar
schultezub committed
55
namespace campvis {
56
57
58
59
    class AbstractPipeline;
    class DataContainer;
    class DataContainerTreeWidget;
    class DataHandle;
60
    class FaceGeometry;
61
    class DataContainerInspectorWidget;
62

63
    class DataContainerInspectorCanvas : public tgt::QtThreadedCanvas, tgt::Painter, public tgt::EventListener, public HasPropertyCollection {
64
65
66
67
68
69
70
        Q_OBJECT;

    public:
        /**
         * Creates a new DataContainerInspectorCanvas.
         * \param   parent          Parent Qt widget, may be 0 (default)
         */
71
        explicit DataContainerInspectorCanvas(QWidget* parent = 0);
72
73
74
75
76
77
78
79
80
81

        /**
         * Destructor.
         */
        ~DataContainerInspectorCanvas();

        /**
         * Initializes the OpenGL stuff (e.g. shaders).
         * Must be called with a valid and locked OpenGL context.
         */
82
        virtual void init(DataContainerInspectorWidget* _pWidget);
83
84
85
86
87
88
89

        /**
         * Deinitializes the OpenGL stuff (e.g. shaders).
         * Must be called with a valid and locked OpenGL context.
         */
        void deinit();

90
        void setDataHandles(const std::vector< std::pair<QString, QtDataHandle> >& handles);
91
92
93
94
95
96
97
98
99
100
        
		/**
         * returns the color value which is captured with the mouse.
         */
		const tgt::Color& getCapturedColor();

		/**
         * returns the depth value which is captured with the mouse.
         */
		const float& getCapturedDepth();
101
102
103
104
105
106
107
108

        /**
         * Size hint for the default window size
         * \return QSize(640, 480)
         */
        QSize sizeHint() const;

        /**
109
         * Schedule a repaint job for the inspector's render target
110
         */
111
        void repaint();
112

113
114
        /// This is meant be overridden to adjust camera settings to new canvas dimensions
        virtual void sizeChanged(const tgt::ivec2&);
115

116
117
118
119
120
121
        /**
         * Called on double click event on this canvas
         * \param   e   Mouse event arguments
         */
        virtual void mouseDoubleClickEvent(tgt::MouseEvent* e);

122
        /**
123
124
125
         * Called on mouse move event on this canvas
         * \param   e   Mouse event arguments
         */
126
        virtual void mouseMoveEvent(tgt::MouseEvent* e);
127

128
129
130
131
132
        /**
         * Called on mouse wheel even on this canvas.
         * \param   e   Mouse event arguments
         */
        virtual void wheelEvent(tgt::MouseEvent* e);
133
134
135
136
137
138
        
        /**
         * Slot getting called when one of the observed properties changed and notifies its observers.
         * \param   prop    Property that emitted the signal
         */
        virtual void onPropertyChanged(const AbstractProperty* prop);
139

140
141
142
        IntProperty p_currentSlice;
        TransferFunctionProperty p_transferFunction;     ///< Transfer function

143
    private slots:
144
145
146
147
148
149
        /**
         * Slot being called when a QtDataHandle has been added to the DataContainer.
         * \param   key     Name of the QtDataHandle
         * \param   dh      The added QtDataHandle
         */
        void onDataContainerChanged(const QString& key, QtDataHandle dh);
150
151

    protected:
152
153
154
155
156
        /**
         * Performs the painting.
         */
        virtual void paint();

157
158
159
160
161
162
        /**
         * Gets called when the data collection of this pipeline has changed and thus has notified its observers.
         * If \a name equals the name of the renderTarget, the s_renderTargetChanged signal will be emitted.
         * \param   name    Name of the added data.
         * \param   dh      DataHandle to the newly added data.
         */
163
        void onDataContainerDataAdded(const std::string& name, const DataHandle& dh);
164

165
166
        /**
         * Updates the textures vector.
167
         * \note Only call with acquired lock and valid OpenGL context!!
168
169
170
         */
        void updateTextures();

171
172
173
174
175
        /**
         * To be called when the canvas is invalidated, issues new paint job.
         */
        void invalidate();

176
        /**
177
         * Renders the given 2D texture.
178
179
180
         * Binds the texture to the shader, sets the uniforms and renders the quad.
         * \param   texture     The texture to render.
         */
181
        void paintTexture(const tgt::Texture* texture, const tgt::TextureUnit& unit2d, const tgt::TextureUnit& unit3d);
182

183
184
185
186
187
188
189
		/**
         * Renders the given 2D texture.
         * Binds the texture to the shader, sets the uniforms and renders the quad.
         * \param   texture     The texture to render.
         */
		void drawGeomtery();

190
191
192
193
        /**
         * Creates the quad used for rendering the textures.
         */
        void createQuad();
194

195
196
        std::map<QString, QtDataHandle> _handles;
        std::vector<const tgt::Texture*> _textures;
197
        bool _texturesDirty;
198

199
        DataContainer* _dataContainer;                  ///< The DataContainer this widget is inspecting
200
        tbb::mutex _localMutex;                         ///< Mutex protecting the local members
201

202
203
        tgt::Shader* _paintShader;                      ///< GLSL shader for rendering the textures
        FaceGeometry* _quad;                            ///< Quad used for rendering
204

205
206
207
        tgt::Color _color;                              ///< Color under the mouse cursor
		float      _depth;								///< Depth under the mouse cursor
        DataContainerInspectorWidget* _widget;          ///< Pointer to the widget which has access to this canvas
208

209
210
211
212
        tgt::ivec2 _numTiles;                           ///< number of tiles on texture overview
        tgt::ivec2 _quadSize;                           ///< size in pixels for each tile in overview
        size_t _selectedTexture;                        ///< index of selected texture for fullscreen view
        bool _renderFullscreen;                         ///< flag whether to render in full screen
213

214
        int _currentSlice;								///< current slice if rendering a 3D image fullscreen, render MIP if negative
215

216
		tgt::Shader* _geomteryRenderingShader;			///< GLSL shader for rendering the geomtery
217
218
219
220
    };
}

#endif // DATACONTAINERINSPECTORCANVAS_H__