datacontainerinspectorcanvas.h 9 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
37
#include "application/gui/qtdatahandle.h"

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

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

47
48
#include <memory>

49

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

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

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

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

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

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

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

92
93
94
95
        /**
         * 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.
         */
96
        void setDataHandles(const std::vector< std::pair<QString, QtDataHandle> >& handles);
97
98
99
100
101
102
103
104

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

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

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

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

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

123
124
125
126
        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
127

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

    signals:
131
        void s_colorChanged(const cgt::vec4&);
132
133
        void s_depthChanged(float depth);

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

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

148
149
150
151
152
153
        /**
         * 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.
         */
154
        void onDataContainerDataAdded(const std::string& name, DataHandle dh);
155

156
        /**
157
158
         * Slot getting called when one of the observed properties changed and notifies its observers.
         * \param   prop    Property that emitted the signal
159
         */
160
161
        virtual void onPropertyChanged(const AbstractProperty* prop);
        virtual void onGeometryRendererPropertyChanged(const AbstractProperty* prop);
162

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

169
170
171
        /**
         * Resets the trackball and reinitializes the camera to the currently loaded geometries if necessary.
         */
172
173
        void resetTrackball();

174
175
176
177
178
        /**
         * To be called when the canvas is invalidated, issues new paint job.
         */
        void invalidate();

179
        /**
180
         * Renders the given 2D texture.
181
         * Binds the texture to the shader, sets the uniforms and renders the quad.
182
         * \param   texture     The texture to render. Must not be 0.
mostajab's avatar
mostajab committed
183
184
         * \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).
185
         */
186
        void paintTexture(const cgt::Texture* texture, const cgt::TextureUnit& unit2d, const cgt::TextureUnit& unit3d);
187

188
        /**
189
190
191
192
         * Renders \a geometry into a texture.
         * 
         * \param name 
         * \param geometry
193
         */
194
        void renderGeometryIntoTexture(const std::string& name, int textureIndex = -1);
195

196
197
198
199
        /**
         * Creates the quad used for rendering the textures.
         */
        void createQuad();
200

201
202
        
        std::map<QString, QtDataHandle> _handles;   ///< Map of DataHandles to show
203
204
205

        /// Vector of textures to render. Each DataHandle contains an ImageData that has an OpenGL representation.
        /// This ensures thread safety.
206
207
208
209
        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;
210

211
212
        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.
213

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

217
        cgt::Shader* _paintShader;                  ///< GLSL shader for rendering the textures
218
        std::unique_ptr<FaceGeometry> _quad;        ///< Quad used for rendering
219

220
221
        cgt::ivec2 _numTiles;                       ///< number of tiles on texture overview
        cgt::ivec2 _quadSize;                       ///< size in pixels for each tile in overview
222

223
224
        DataContainer _localDataContainer;          ///< Local DataContainer the GeometryRenderer works on
        IVec2Property p_viewportSize;
225
226

        TrackballCameraProvider _tcp;               ///< TrackballCameraProvider to do camera stuff
227
        GeometryRenderer _geometryRenderer;         ///< GeometryRenderer used to render geometries
228
229
230
    };
}

231
#endif // DATACONTAINERINSPECTORCANVAS_H__