2d/fuzzyclustersolver_cg.hh
Go to the documentation of this file.
1 /* -*- mia-c++ -*-
2  *
3  * This file is part of MIA - a toolbox for medical image analysis
4  * Copyright (c) Leipzig, Madrid 1999-2017 Gert Wollny
5  *
6  * MIA is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with MIA; if not, see <http://www.gnu.org/licenses/>.
18  *
19  */
20 
21 #ifndef __SOLVERCG_HH
22 #define __SOLVERCG_HH
23 
24 #ifdef HAVE_CONFIG_H
25 #include <config.h>
26 #endif
27 
28 #include <mia/2d.hh>
29 #include <cstdio>
30 #include <stdexcept>
31 #include <string>
32 
33 
34 
36 
37 using namespace std;
38 
39 
40 
48 extern bool fborder (long index, long nx, long ny);
49 
62 class C2DSolveCG {
63 
64  private:
65  double m_lambda1;
66  double m_lambda2;
67 
68  // Dimension of images
69  long m_iter;
70  int m_nx, m_ny;
71  unsigned long m_count;
72 
73  // Pointer to Elements of w
74  float *m_weight_imagePtr;
75  float *m_fptr;
76  float *m_gain_image_ptr;
77 
78 
79 
80  // b and x for solution of system
81  std::vector<double> m_b;
82  std::vector<double> m_v;
83 
84  // counts iterations
85 
86 
87  // help pointers for one iteration cycle
88  std::vector<double> m_r; // r^(k)
89  std::vector<double> m_rho; // p^(k)
90  std::vector<double> m_g;
91  std::vector<double> m_Ag; // speichert A * p
92  // Field of scaling factors
93  std::vector<double> m_scale;
94  std::vector<double> m_scale2;
95 
96  // field for border voxels
97  std::vector<bool> m_border;
98 
99 
100  double m_r1rho1; // speichert r1 * rho1
101  double m_r2rho2; // speichert r2 * rho2
102  double m_normr0;
103  double m_q, m_e, m_sprod;
104 
105  // minimal residuum
106  double m_min_res, m_relres;
107 
110  void init();
111 
112  public:
122  C2DSolveCG (C2DFImage& w1, C2DFImage& f1, C2DFImage& g1, double l1, double l2, double r_res, double m_res);
123 
124  ~C2DSolveCG();
125 
131  int solve(long max_iterations, double *firstnormr0);
132 
136  inline long get_iterations() {return m_iter;}
137 
147  void multA(std::vector<double>& x, std::vector<double>& result, long start, long ende);
148 
156  void multA_float(float *x, float *result);
157 
161  void get_solution(C2DFImage& gain);
162 
166  void add_to_solution(C2DFImage *e);
167 
173  void solvepar(long *max_iteration, double *normr, double *firstnormr0);
174 
175 };
176 
178 
179 #endif
#define NS_MIA_BEGIN
conveniance define to start the mia namespace
Definition: defines.hh:33
bool fborder(long index, long nx, long ny)
function defining field borders
solve_sCG – a class providing a CG solver
#define NS_MIA_END
conveniance define to end the mia namespace
Definition: defines.hh:36