GRALE
monopolegrid.h
1 /*
2 
3  This file is a part of GRALE, a library to facilitate the simulation
4  and inversion of gravitational lenses.
5 
6  Copyright (C) 2008-2012 Jori Liesenborgs
7 
8  Contact: jori.liesenborgs@gmail.com
9 
10  This program is free software; you can redistribute it and/or modify
11  it under the terms of the GNU General Public License as published by
12  the Free Software Foundation; either version 2 of the License, or
13  (at your option) any later version.
14 
15  This program is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  GNU General Public License for more details.
19 
20  You should have received a copy of the GNU General Public License
21  along with this program; if not, write to the Free Software
22  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23 
24 */
25 
26 #ifndef GRALE_MONOPOLEGRID_H
27 
28 #define GRALE_MONOPOLEGRID_H
29 
30 #include "graleconfig.h"
31 #include "monopolebasisfunction.h"
32 #include <errut/errorbase.h>
33 #include <serut/serializationinterface.h>
34 #include <vector>
35 #include <list>
36 
37 namespace grale
38 {
39 
40 class ImagesData;
41 
42 class GRALE_IMPORTEXPORT MonopoleGrid : public errut::ErrorBase
43 {
44 public:
45  MonopoleGrid();
46  ~MonopoleGrid();
47 
48  bool init(const std::list<ImagesData *> images, const Real2DDerivableFunction &target,
49  Vector2D<double> center, double areaSize, int subDiv = 32, double zeroPointFactor = 2.0);
50 
51  int getNumberOfBasisFunctions() const { return m_monoPoleFunctions.size(); }
52  void setBasisWeights(const std::vector<double> &w) { if (w.size() == m_monoPoleWeights.size()) m_monoPoleWeights = w; }
53 
54  double getZeroPoint(int i) const { return m_monoPoleFunctions[i].getZeroPoint(); }
55  double getLengthScale(int i) const { return m_monoPoleFunctions[i].getLengthScale(); }
56  Vector2D<double> getPosition(int i) const { return m_monoPoleCenters[i]; }
57 
58  void prepareFitnessCalculation();
59  void calculateFitness(double *pFlatness, double *pNegative, double scale);
60 
61  bool write(serut::SerializationInterface &si) const;
62  bool read(serut::SerializationInterface &si);
63 private:
64  void clear();
65 
66  std::vector<MonopoleBasisFunction> m_monoPoleFunctions;
67  std::vector<Vector2D<double> > m_monoPoleCenters;
68  std::vector<double> m_monoPoleWeights;
69  std::vector<std::vector<int> > m_pixelDependencies;
70 
71  std::vector<double> m_targetMap;
72  std::vector<Vector2D<double> > m_targetGradientMap;
73 
74  std::vector<double> m_monoPoleMap;
75  std::vector<Vector2D<double> > m_monoPoleGradientMap;
76 
77  Vector2D<double> m_bottomLeft;
78  double m_stepSize;
79  int m_subDiv;
80 };
81 
82 } // end namespace
83 
84 #endif // GRALE_MONOPOLEGRID_H