OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
solution.h
Go to the documentation of this file.
1 //$$ solution.h // solve routines
2 
3 // #include <ossim/matrix/boolean.h>
5 
6 #ifdef use_namespace
7 namespace RBD_COMMON {
8 #endif
9 
10 
11 // Solve the equation f(x)=y for x where f is a monotone continuous
12 // function of x
13 // Essentially Brent s method
14 
15 // You need to derive a class from R1_R1 and override "operator()"
16 // with the function you want to solve.
17 // Use an object from this class in OneDimSolve
18 
19 class R1_R1
20 {
21  // the prototype for a Real function of a Real variable
22  // you need to derive your function from this one and put in your
23  // function for operator() at least. You probably also want to set up a
24  // constructor to put in additional parameter values (e.g. that will not
25  // vary during a solve)
26 
27 protected:
28  Real x; // Current x value
29  bool xSet; // true if a value assigned to x
30 
31 public:
32  virtual ~R1_R1();
33 
34  Real minX, maxX; // range of value x
35  bool minXinf, maxXinf; // true if these are infinite
36  R1_R1() : xSet(false), minXinf(true), maxXinf(true) {}
37  virtual Real operator()() = 0; // function value at current x
38  // set current x
39  virtual void Set(Real X); // set x, check OK
40  Real operator()(Real X) { Set(X); return operator()(); }
41  // set x, return value
42  virtual bool IsValid(Real X);
43  operator Real(); // implicit conversion
44 };
45 
46 class SolutionException : public Exception
47 {
48 public:
49  static unsigned long Select;
50  SolutionException(const char* a_what = 0);
51 };
52 
54 {
55  R1_R1& function; // reference to the function
56  Real accX; // accuracy in X direction
57  Real accY; // accuracy in Y direction
58  int lim; // maximum number of iterations
59 
60 public:
61  OneDimSolve(R1_R1& f, Real AccY = 0.0001, Real AccX = 0.0)
62  : function(f), accX(AccX), accY(AccY) {}
63  // f is an R1_R1 function
64  Real Solve(Real Y, Real X, Real Dev, int Lim=100);
65  // Solve for x in Y=f(x)
66  // X is the initial trial value of x
67  // X+Dev is the second trial value
68  // program returns a value of x such that
69  // |Y-f(x)| <= accY or |f.inv(Y)-x| <= accX
70 
71 private:
72  Real x[3], y[3]; // Trial values of X and Y
73  int L,C,U,Last; // Locations of trial values
74  int vpol, hpol; // polarities
75  Real YY; // target value
76  int i;
77  void LookAt(int); // get new value of function
78  bool Finish; // true if LookAt finds conv.
79  bool Captured; // true when target surrounded
80  void VFlip();
81  void HFlip();
82  void Flip();
83  void State(int I, int J, int K);
84  void Linear(int, int, int);
85  void Quadratic(int, int, int);
86 };
87 
88 
89 #ifdef use_namespace
90 }
91 #endif
92 
93 // body file: solution.cpp
94 
95 
96 
ossim_uint32 x
R1_R1()
Definition: solution.h:36
double Real
Definition: include.h:57
Real accX
Definition: solution.h:56
bool minXinf
Definition: solution.h:35
OneDimSolve(R1_R1 &f, Real AccY=0.0001, Real AccX=0.0)
Definition: solution.h:61
bool xSet
Definition: solution.h:29
ossim_uint32 y
bool Finish
Definition: solution.h:78
Real minX
Definition: solution.h:34
int vpol
Definition: solution.h:74
Real operator()(Real X)
Definition: solution.h:40
Definition: solution.h:19
Real x
Definition: solution.h:28
Real YY
Definition: solution.h:75
static unsigned long Select
Definition: solution.h:49
bool Captured
Definition: solution.h:79
Real accY
Definition: solution.h:57