datacontainerinspectorcanvas.h 8.67 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-2015, 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 DATACONTAINERINSPECTORCANVAS_H__
#define DATACONTAINERINSPECTORCANVAS_H__

#include "sigslot/sigslot.h"
29
30
31
32
33
#include "cgt/painter.h"
#include "cgt/event/eventlistener.h"
#include "cgt/event/mouseevent.h"
#include "cgt/glcontextmanager.h"
#include "cgt/qt/qtthreadedcanvas.h"
schultezub's avatar
schultezub committed
34
#include "tbb/mutex.h"
35

36
#include "application/applicationapi.h"
37
38
#include "application/gui/qtdatahandle.h"

39
#include "core/properties/metaproperty.h"
40
#include "core/properties/numericproperty.h"
41
#include "core/properties/propertycollection.h"
42
#include "core/properties/transferfunctionproperty.h"
43
44

#include "modules/base/processors/lightsourceprovider.h"
45
#include "modules/base/processors/trackballcameraprovider.h"
46
#include "modules/vis/processors/geometryrenderer.h"
47

48
49
#include <memory>

50

51
namespace cgt {
52
53
    class Shader;
    class Texture;
54
    class TextureUnit;
55
56
}

schultezub's avatar
schultezub committed
57
namespace campvis {
58
59
60
61
    class AbstractPipeline;
    class DataContainer;
    class DataContainerTreeWidget;
    class DataHandle;
62
    class FaceGeometry;
63
    class GeometryData;
64
    class DataContainerInspectorWidget;
65

66
    class CAMPVIS_APPLICATION_API DataContainerInspectorCanvas : public cgt::QtThreadedCanvas, cgt::Painter, public cgt::EventListener, public HasPropertyCollection {
67
68
69
70
71
72
73
        Q_OBJECT;

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

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

        /**
         * Initializes the OpenGL stuff (e.g. shaders).
         * Must be called with a valid and locked OpenGL context.
         */
85
        virtual void init();
86
87
88
89
90
91
92

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

93
94
95
96
        /**
         * Set the DataHandles to show in the canvas to those in \a handles.
         * \param   handles vector of name-DataHandle pairs to show in the canvas.
         */
97
        void setDataHandles(const std::vector< std::pair<QString, QtDataHandle> >& handles);
98
99
100
101
102
103
104
105

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

        /**
106
         * Schedule a repaint job for the inspector's render target
107
         */
108
        void repaint();
109

110
        /// This is meant be overridden to adjust camera settings to new canvas dimensions
111
        virtual void sizeChanged(const cgt::ivec2&);
112

113
        /**
114
115
116
         * Called on mouse move event on this canvas
         * \param   e   Mouse event arguments
         */
117
        virtual void mouseMoveEvent(cgt::MouseEvent* e);
118

119
        virtual void onEvent(cgt::Event* e);
120
        
121
122
        IntProperty p_currentSlice;                     ///< Currently selected slice to show
        TransferFunctionProperty p_transferFunction;    ///< Transfer function
123

124
125
126
127
        BoolProperty p_renderRChannel;                  ///< Flag whether to render Red channel
        BoolProperty p_renderGChannel;                  ///< Flag whether to render Green channel
        BoolProperty p_renderBChannel;                  ///< Flag whether to render Blue channel
        BoolProperty p_renderAChannel;                  ///< Flag whether to render Alpha channel
128

129
        MetaProperty p_geometryRendererProperties;      ///< MetaProperty for the GeometryRenderer
130
131

    signals:
132
133
        void s_colorChanged(const cgt::svec3& texel, const cgt::vec4&);
        void s_depthChanged(const cgt::svec3& texel, float depth);
134

135
    private slots:
136
137
138
139
140
141
        /**
         * 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);
142
143

    protected:
144
145
146
147
148
        /**
         * Performs the painting.
         */
        virtual void paint();

149
        /**
150
151
         * Slot getting called when one of the observed properties changed and notifies its observers.
         * \param   prop    Property that emitted the signal
152
         */
153
154
        virtual void onPropertyChanged(const AbstractProperty* prop);
        virtual void onGeometryRendererPropertyChanged(const AbstractProperty* prop);
155

156
        /**
157
         * Updates the textures vector.
158
159
         * \note Only call with acquired lock and valid OpenGL context!!
         */
160
        void updateTextures();
161

162
163
164
        /**
         * Resets the trackball and reinitializes the camera to the currently loaded geometries if necessary.
         */
165
166
        void resetTrackball();

167
168
169
170
171
        /**
         * To be called when the canvas is invalidated, issues new paint job.
         */
        void invalidate();

172
        /**
173
         * Renders the given 2D texture.
174
         * Binds the texture to the shader, sets the uniforms and renders the quad.
175
         * \param   texture     The texture to render. Must not be 0.
mostajab's avatar
mostajab committed
176
177
         * \param   uint2d      The texture unit that will be attached to rendering pipeline (2D for 2D textures).
         * \param   uint2d      The texture unit that will be attached to rendering pipeline (3D for 3D textures).
178
         */
179
        void paintTexture(const cgt::Texture* texture, const cgt::TextureUnit& unit2d, const cgt::TextureUnit& unit3d);
180

181
        /**
182
183
184
185
         * Renders \a geometry into a texture.
         * 
         * \param name 
         * \param geometry
186
         */
187
        void renderGeometryIntoTexture(const std::string& name, int textureIndex = -1);
188

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

194
195
        
        std::map<QString, QtDataHandle> _handles;   ///< Map of DataHandles to show
196
197
198

        /// Vector of textures to render. Each DataHandle contains an ImageData that has an OpenGL representation.
        /// This ensures thread safety.
199
200
201
202
        std::vector<QtDataHandle> _textures;

        /// List of the names of all rendered geometries. This simplifies to update their rendering.
        std::vector< std::pair<std::string, int> > _geometryNames;
203

204
205
        bool _texturesDirty;                        ///< Flag that shows that the textures need update or not.
        bool _geometriesDirty;                      ///< Flag that shows that the rendered geometries need update or not.
206

mostajab's avatar
mostajab committed
207
208
        DataContainer* _dataContainer;              ///< The DataContainer this widget is inspecting
        tbb::mutex _localMutex;                     ///< Mutex protecting the local members
209

210
        cgt::Shader* _paintShader;                  ///< GLSL shader for rendering the textures
211
        std::unique_ptr<FaceGeometry> _quad;        ///< Quad used for rendering
212

213
214
        cgt::ivec2 _numTiles;                       ///< number of tiles on texture overview
        cgt::ivec2 _quadSize;                       ///< size in pixels for each tile in overview
215

216
217
        DataContainer _localDataContainer;          ///< Local DataContainer the GeometryRenderer works on
        IVec2Property p_viewportSize;
218
219

        TrackballCameraProvider _tcp;               ///< TrackballCameraProvider to do camera stuff
220
        GeometryRenderer _geometryRenderer;         ///< GeometryRenderer used to render geometries
221
222
223
    };
}

224
#endif // DATACONTAINERINSPECTORCANVAS_H__