datacontainerinspectorcanvas.h 7.2 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
8
9
//      Chair for Computer Aided Medical Procedures
//      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
47
48
49
50
#include "core/tools/opengljobprocessor.h"

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

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

61
    class DataContainerInspectorCanvas : public tgt::QtThreadedCanvas, tgt::Painter, public tgt::EventListener, public HasPropertyCollection {
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
        Q_OBJECT;

    public:
        /**
         * Creates a new DataContainerInspectorCanvas.
         * \param   parent          Parent Qt widget, may be 0 (default)
         */
        DataContainerInspectorCanvas(QWidget* parent = 0);

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

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

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

88
        void setDataHandles(const std::vector< std::pair<QString, QtDataHandle> >& handles);
89
90
91
92
93
94
95
96
97
98
99
100

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

        /**
         * Performs the painting.
         */
        void paint();

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

104
105
106
107
108
109
        /**
         * Called on double click event on this canvas
         * \param   e   Mouse event arguments
         */
        virtual void mouseDoubleClickEvent(tgt::MouseEvent* e);

110
111
112
113
114
        /**
         * Called on mouse wheel even on this canvas.
         * \param   e   Mouse event arguments
         */
        virtual void wheelEvent(tgt::MouseEvent* e);
115
116
117
118
119
120
        
        /**
         * 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);
121

122
123
124
        IntProperty p_currentSlice;
        TransferFunctionProperty p_transferFunction;     ///< Transfer function

125
    private slots:
126
127
128
129
130
131
        /**
         * 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);
132
133
134
135
136
137
138
139

    protected:
        /**
         * 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.
         */
140
        void onDataContainerDataAdded(const std::string& name, const DataHandle& dh);
141

142
143
144
145
146
147
        /**
         * Updates the textures vector.
         * \note Only call with acquired lock!!
         */
        void updateTextures();

148
149
150
151
152
        /**
         * To be called when the canvas is invalidated, issues new paint job.
         */
        void invalidate();

153
        /**
154
         * Renders the given 2D texture.
155
156
157
         * Binds the texture to the shader, sets the uniforms and renders the quad.
         * \param   texture     The texture to render.
         */
158
        void paintTexture(const tgt::Texture* texture, const tgt::TextureUnit& unit2d, const tgt::TextureUnit& unit3d);
159

160
161
162
163
        /**
         * Creates the quad used for rendering the textures.
         */
        void createQuad();
164

165
166
167
        std::map<QString, QtDataHandle> _handles;
        std::vector<const tgt::Texture*> _textures;

168
        DataContainer* _dataContainer;                  ///< The DataContainer this widget is inspecting
169
        tbb::mutex _localMutex;                         ///< Mutex protecting the local members
170

171
172
        tgt::Shader* _paintShader;                      ///< GLSL shader for rendering the textures
        FaceGeometry* _quad;                            ///< Quad used for rendering
173

174
175
176
177
        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
178

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

181
182
183
184
    };
}

#endif // DATACONTAINERINSPECTORCANVAS_H__