nloptregistration.h 4.93 KB
Newer Older
1
2
3
4
// ================================================================================================
// 
// This file is part of the CAMPVis Software Framework.
// 
5
// If not explicitly stated otherwise: Copyright (C) 2012-2015, all rights reserved,
6
7
//      Christian Schulte zu Berge <christian.szb@in.tum.de>
//      Chair for Computer Aided Medical Procedures
8
9
//      Technische Universitaet Muenchen
//      Boltzmannstr. 3, 85748 Garching b. Muenchen, Germany
10
// 
11
12
// For a full list of authors and contributors, please refer to the file "AUTHORS.txt".
// 
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
#ifndef NLOPTREGISTRATION_H__
#define NLOPTREGISTRATION_H__
27
28
29
30
31

#include "core/datastructures/imagerepresentationlocal.h"
#include "core/eventhandlers/mwheeltonumericpropertyeventlistener.h"
#include "core/eventhandlers/transfuncwindowingeventlistener.h"
#include "core/pipeline/autoevaluationpipeline.h"
32

33
#include "modules/modulesapi.h"
34
#include "modules/base/processors/lightsourceprovider.h"
35
#include "modules/io/processors/mhdimagereader.h"
36
#include "modules/vis/processors/volumeexplorer.h"
37
38
#include "modules/preprocessing/processors/gradientvolumegenerator.h"
#include "modules/preprocessing/processors/lhhistogram.h"
39
#include "modules/registration/processors/registrationsliceview.h"
40
41
#include "modules/registration/processors/similaritymeasure.h"

42
43
#include <nlopt.hpp>

44
namespace campvis {
45
46
namespace registration {

47
    class CAMPVIS_MODULES_API NloptRegistration : public AutoEvaluationPipeline {
48
49
    public:
        /**
50
51
52
         * Creates a NloptRegistration pipeline.
         * \param   dataContainer   Reference to the DataContainer containing local working set of data
         *                          for this pipeline, must be valid the whole lifetime of this pipeline.
53
         */
54
        explicit NloptRegistration(DataContainer& dataContainer);
55
56
57
58

        /**
         * Virtual Destructor
         **/
59
        virtual ~NloptRegistration();
60
61
62

        /// \see AutoEvaluationPipeline::init()
        virtual void init();
63
64
        /// \see AutoEvaluationPipeline::deinit()
        virtual void deinit();
65

66
        static const std::string getId() { return "registration::NloptRegistration"; };
67
68
69
70
71

        GenericOptionProperty<nlopt::algorithm> p_optimizer;    ///< Optimizer Algorithm
        BoolProperty p_liveUpdate;                              ///< Live Update of the difference image
        ButtonProperty p_performOptimization;                   ///< Start Optimization
        ButtonProperty p_forceStop;                             ///< Stop Optimization
72

73
74
        FloatProperty p_translationStepSize;                    ///< Initial Step Size for Translation
        FloatProperty p_rotationStepSize;                       ///< Initial Step Size for Rotation
75
76

    protected:
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
        /// Auxiliary data structure for nlopt
        struct MyFuncData_t {
            NloptRegistration* _object;
            const ImageRepresentationGL* _reference;
            const ImageRepresentationGL* _moving;
            size_t _count;
        };

        /**
         * Callback method called from p_performOptimization.
         * (Does not need an OpenGL context)
         */
        void onPerformOptimizationClicked();
        
        /**
         * Perform optimization to register \a movingImage to \a referenceImage.
         * \note    Needs to be called from a valid OpenGL context!
         */
        void performOptimization();

        /**
         * Free function to be called by nlopt optimizer computing the similarity.
         * \note    Needs to be called from a valid OpenGL context!
         * \param   x               Optimization vector
         * \param   grad            Gradient vector (currently ignored!)
         * \param   my_func_data    Auxiliary data structure0
         * \return  Result of the cost function.
         */
        static double optimizerFunc(const std::vector<double>& x, std::vector<double>& grad, void* my_func_data);

        /**
         * Stop the Optimization process.
         */
        void forceStop();


113
        LightSourceProvider _lsp;
114
115
        MhdImageReader _referenceReader;
        MhdImageReader _movingReader;
116
        RegistrationSliceView _rsw;
117
        SimilarityMeasure _sm;
118
        VolumeExplorer _ve;
119
        
120
        nlopt::opt* _opt;                               ///< Pointer to nlopt Optimizer object
121
122
123
124
    };

}

125
126
}

127
#endif // NLOPTREGISTRATION_H__