microscopyimagesegmentation.h 9.32 KB
Newer Older
Hossain Mahmud's avatar
Hossain Mahmud committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
// ================================================================================================
// 
// This file is part of the CAMPVis Software Framework.
// 
// If not explicitly stated otherwise: Copyright (C) 2012-2014, all rights reserved,
//      Christian Schulte zu Berge <christian.szb@in.tum.de>
//      Chair for Computer Aided Medical Procedures
//      Technische Universitaet Muenchen
//      Boltzmannstr. 3, 85748 Garching b. Muenchen, Germany
// 
// For a full list of authors and contributors, please refer to the file "AUTHORS.txt".
// 
// 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
// 
// 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.
// 
// ================================================================================================

#ifndef MICROSCOPYIMAGESEGMENTATION_H__
#define MICROSCOPYIMAGESEGMENTATION_H__

28
#include "cgt/event/eventlistener.h"
Hossain Mahmud's avatar
Hossain Mahmud committed
29
30
31
32
33
34
35

#include "core/eventhandlers/mwheeltonumericpropertyeventlistener.h"
#include "core/eventhandlers/transfuncwindowingeventlistener.h"

#include "core/pipeline/abstractprocessordecorator.h"
#include "core/pipeline/visualizationprocessor.h"

36
#include "core/properties/allproperties.h"
Hossain Mahmud's avatar
Hossain Mahmud committed
37
#include "core/properties/colorproperty.h"
38
#include "core/datastructures/facegeometry.h"
Hossain Mahmud's avatar
Hossain Mahmud committed
39

40
#include "modules/modulesapi.h"
41
#include "modules/base/processors/trackballcameraprovider.h"
Hossain Mahmud's avatar
Hossain Mahmud committed
42
43
#include "modules/vis/processors/volumerenderer.h"
#include "modules/vis/processors/sliceextractor.h"
44

Hossain Mahmud's avatar
Hossain Mahmud committed
45
#include <vector>
46
47
#include <memory>
#include "core/datastructures/facegeometry.h"
Hossain Mahmud's avatar
Hossain Mahmud committed
48

49
namespace cgt {
Hossain Mahmud's avatar
Hossain Mahmud committed
50
51
52
53
54
55
56
57
58
    class Shader;
}

//class FaceGeometry;

namespace campvis {    
    /**
     * Structure to store the informations related to a contour object.
     */
59
    class CAMPVIS_MODULES_API ContourObject {
Hossain Mahmud's avatar
Hossain Mahmud committed
60
61
62
    public:
        ContourObject(std::string name);
        virtual ~ContourObject();
63
        ContourObject& operator=(const ContourObject& rhs);
Hossain Mahmud's avatar
Hossain Mahmud committed
64
65
66
67
68
        void addObject();

        StringProperty _objectName;
        ColorProperty _color;                       ///< Color of the Object
        BoolProperty _visibility;
69
        std::vector<cgt::ivec3> _points;            ///< List of points for the current object being painted
Hossain Mahmud's avatar
Hossain Mahmud committed
70

71
        std::vector< std::vector<cgt::ivec3> > _objectsCoordinates;         ///< List of previously painted contours
Hossain Mahmud's avatar
Hossain Mahmud committed
72
73
74
75
76
77
78
79
80
81
82
83
84
    protected:
        enum {
            CONTOUR = 0,
            PAINTED = 1,
        };

    private:
    };
    
    /**
     * Defines a proxy FaceGeometry to pass to SliceExtractor and render()
     * Thus also overloads the render() function.
     */
85
    class CAMPVIS_MODULES_API ProxyFaceGeometry : public FaceGeometry {
Hossain Mahmud's avatar
Hossain Mahmud committed
86
87
88
89
90
91
92
93
94
95
96
97
98
    public:
        void addGeometry(FaceGeometry geometry);
        void render(GLenum mode) const;
    protected:

    private:
        std::vector<FaceGeometry> _geometries;
    };


    /**
     * Combines a volume raycaster and 3 slice views for graphical segmentation of slices through user input.
     */
99
    class CAMPVIS_MODULES_API MicroscopyImageSegmentation : public VisualizationProcessor, public HasProcessorDecorators, public cgt::EventListener {
Hossain Mahmud's avatar
Hossain Mahmud committed
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
    public:
        /**
         * Constructs a new MicroscopyImageSegmentation Processor
         * \param   viewportSizeProp    Pointer to the property defining the viewport size, must not be 0.
         * \param   raycaster           Raycaster to use for rendering, must not be 0, VolumeRenderer will take ownership.
         **/
        MicroscopyImageSegmentation(IVec2Property* viewportSizeProp, RaycastingProcessor* raycaster = new SimpleRaycaster(0));

        /**
         * Destructor
         **/
        virtual ~MicroscopyImageSegmentation();

        /// \see AbstractProcessor::init
        virtual void init();

        /// \see AbstractProcessor::deinit
        virtual void deinit();
118
119
120
121
122
        
        /** 
         * To be used in ProcessorFactory static methods
         */
        static const std::string getId() { return "MicroscopyImageSegmentation"; };
Hossain Mahmud's avatar
Hossain Mahmud committed
123
        /// \see AbstractProcessor::getName()
124
        virtual const std::string getName() const { return getId(); };
Hossain Mahmud's avatar
Hossain Mahmud committed
125
126
127
128
129
130
131
        /// \see AbstractProcessor::getDescription()
        virtual const std::string getDescription() const { return "Combines a volume raycaster and 3 slice views for explorative volume visualization."; };
        /// \see AbstractProcessor::getAuthor()
        virtual const std::string getAuthor() const { return "Christian Schulte zu Berge <christian.szb@in.tum.de>"; };
        /// \see AbstractProcessor::getProcessorState()
        virtual ProcessorState getProcessorState() const { return AbstractProcessor::EXPERIMENTAL; };
        
132
133
        /// \see cgt::EventListener::onEvent()
        virtual void onEvent(cgt::Event* e);
Hossain Mahmud's avatar
Hossain Mahmud committed
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172

        DataNameProperty p_inputVolume;     ///< image ID for first input image
        DataNameProperty p_outputImage;     ///< image ID for output image

        BoolProperty p_enableScribbling;    ///< Enable Scribbling in Slice Views

        MetaProperty p_seProperties;        ///< MetaProperty for SliceExtractor properties
        MetaProperty p_vrProperties;        ///< MetaProperty for Raycaster properties


    protected:
        /// Additional invalidation levels for this processor.
        /// Not the most beautiful design though.
        enum ProcessorInvalidationLevel {
            VR_INVALID = FIRST_FREE_TO_USE_INVALIDATION_LEVEL,
            SLICES_INVALID = FIRST_FREE_TO_USE_INVALIDATION_LEVEL << 1,
            SCRIBBLE_INVALID = FIRST_FREE_TO_USE_INVALIDATION_LEVEL << 2,
            AXISSCALE_INVALID = FIRST_FREE_TO_USE_INVALIDATION_LEVEL << 3,
        };

        /// \see AbstractProcessor::updateResult
        virtual void updateResult(DataContainer& dataContainer);

        /**
         * Slot getting called when one of the observed processors got invalidated.
         * Invalidates this meta-processor with the corresponding level.
         * \param   processor   The processor that emitted the signal
         */
        virtual void onProcessorInvalidated(AbstractProcessor* processor);

        /**
         * \see VisualizationProcessor::onPropertyChanged
         */
        virtual void onPropertyChanged(const AbstractProperty* prop);

        /**
         * Callback called from SliceExtractor when a scribble has been painted.
         * \param   voxel   Voxel position of scribble
         */
173
        void onSliceExtractorScribblePainted(cgt::vec3 voxel);
Hossain Mahmud's avatar
Hossain Mahmud committed
174
175
176
177
178
179

        void composeFinalRendering(DataContainer& data);

        /// \see    AbstractProcessor::updateProperties
        void updateProperties(DataContainer& dc);

180
        cgt::Shader* _shader;                           ///< Shader for slice rendering
181
        std::unique_ptr<FaceGeometry> _quad;
Hossain Mahmud's avatar
Hossain Mahmud committed
182

183
        TrackballCameraProvider _tcp;
Hossain Mahmud's avatar
Hossain Mahmud committed
184
185
186
187
188
189
190
        VolumeRenderer _vr;
        SliceExtractor _sliceExtractor;

        IVec2Property p_rightPaneBlockSize;             ///< Used for defining space for volume explorer, xslice, yslice
        IVec2Property p_leftPaneSize;                   ///< Used to define space for zslice
        IVec2Property p_zSize;                          ///< Actual size for zslice

191
192
193
194
195
        MWheelToNumericPropertyEventListener _xSliceHandler;
        MWheelToNumericPropertyEventListener _ySliceHandler;
        MWheelToNumericPropertyEventListener _zSliceHandler;
        TransFuncWindowingEventListener _windowingHandler;

Hossain Mahmud's avatar
Hossain Mahmud committed
196
197
        ColorProperty p_paintColor;                     ///< Color picker for active object
        Vec3Property p_axisScaling;                     ///< Asis ratio. Used to change ImageMappingInformation
198
        cgt::vec3 _oldScaling;
Hossain Mahmud's avatar
Hossain Mahmud committed
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223

        BoolProperty p_fitToWindow;                         ///< Flag whether fit image to window or use scaling and offset
        FloatProperty p_scalingFactor;                      ///< Image scaling factor
        IVec2Property p_offset;                             ///< Image offset

        ButtonProperty p_addObject;                     ///< Add a contour object
        ButtonProperty p_deleteObject;                  ///< Delete the current object
        StringProperty p_csvPath;                       ///< Filepath to save CSV
        ButtonProperty p_saveCSV;                       ///< Save changes in CSV
        GenericOptionProperty<ContourObject> *p_objectList; ///< List of drawn contours
        bool _mousePressedInRaycaster;                  ///< Flag whether mouse was pressed in raycaster

        static const std::string loggerCat_;

    private:
        void onAddButtonClicked();
        void onDeleteButtonClicked();
        void onSaveCSVButtonClicked();
        void onCSVFileSelected(const AbstractProperty *prop);
        void onObjectSelectionChanged(const AbstractProperty *prop);
        void onPaintColorChanged(const AbstractProperty *prop);

        void addProperties();
        void removeProperties();

224
        double distanceSqr(cgt::vec3 src, cgt::vec3 dest);
Hossain Mahmud's avatar
Hossain Mahmud committed
225
226
227
228
229
230
231
232
233

        std::string _objectNamePrefix;
        int _objectNameSuffix;
        bool editVoxel;
        int insertNextVoxelAt;
    };
}

#endif // MICROSCOPYIMAGESEGMENTATION_H__