2.12.2021, 9:00 - 11:00: Due to updates GitLab may be unavailable for some minutes between 09:00 and 11:00.

datacontainerinspectorcanvas.h 8.98 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-2014, 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
29
// 
// ================================================================================================

#ifndef DATACONTAINERINSPECTORCANVAS_H__
#define DATACONTAINERINSPECTORCANVAS_H__

#include "sigslot/sigslot.h"
#include "tgt/painter.h"
30
31
#include "tgt/event/eventlistener.h"
#include "tgt/event/mouseevent.h"
32
#include "tgt/glcontextmanager.h"
33
#include "tgt/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
#include "core/tools/opengljobprocessor.h"
43
44
45
#include "core/eventhandlers/trackballnavigationeventlistener.h"

#include "modules/base/processors/lightsourceprovider.h"
46
#include "modules/vis/processors/geometryrenderer.h"
47
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 GeometryData;
62
    class DataContainerInspectorWidget;
63

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

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

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

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

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

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

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

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

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

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

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

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

127
        MetaProperty p_geometryRendererProperties;      ///< MetaProperty for the GeometryRenderer
128
129
130
131
132

    signals:
        void s_colorChanged(const tgt::vec4&);
        void s_depthChanged(float depth);

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

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

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

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

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

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

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

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

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

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

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

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

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

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

mostajab's avatar
mostajab committed
216
217
        tgt::Shader* _paintShader;                  ///< GLSL shader for rendering the textures
        FaceGeometry* _quad;                        ///< Quad used for rendering
218

mostajab's avatar
mostajab committed
219
220
        tgt::ivec2 _numTiles;                       ///< number of tiles on texture overview
        tgt::ivec2 _quadSize;                       ///< size in pixels for each tile in overview
221

222
223
224
225
        DataContainer _localDataContainer;          ///< Local DataContainer the GeometryRenderer works on
        IVec2Property p_viewportSize;
        GeometryRenderer _geometryRenderer;         ///< GeometryRenderer used to render geometries
        TrackballNavigationEventListener* _trackballEH;
226
227
228
    };
}

229
#endif // DATACONTAINERINSPECTORCANVAS_H__