Updated FSF address in all files. Fixes ticket:51
[debian/gnuradio] / ezdop / src / host / hunter / src / search.h
1 /*
2  Copyright 2006 Johnathan Corgan.
3  
4  This program is free software; you can redistribute it and/or modify
5  it under the terms of the GNU General Public License version 2
6  as published by the Free Software Foundation.
7  
8  This software is distributed in the hope that it will be useful,
9  but WITHOUT ANY WARRANTY; without even the implied warranty of
10  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11  GNU General Public License for more details.
12  
13  You should have received a copy of the GNU General Public License
14  along with GNU Radio; see the file COPYING.  If not, write to
15  the Free Software Foundation, Inc., 51 Franklin Street,
16  Boston, MA 02110-1301, USA.
17 */
18
19 #ifndef __SEARCH_H__
20 #define __SEARCH_H__
21
22 // Application level includes
23 #include "spherical.h"
24 #include "samplelog.h"
25 #include "histogram.h"
26
27 // wxWidgets includes
28 #include <wx/event.h>
29
30 // System level includes
31 #include <ctime>
32
33 // Forward declarations
34 class wxFile;
35 class Sample;
36 class TransmitterSearch;
37
38 class SearchUpdate : public wxNotifyEvent
39 {
40 public:
41     SearchUpdate(const wxEventType &event, bool done);
42     virtual wxEvent *Clone() const { return new SearchUpdate(*this); }
43     bool m_done;
44 };
45
46 extern const wxEventType wxEVT_SEARCH_UPDATE;
47
48 typedef void(wxEvtHandler::*SearchUpdateFunction)(SearchUpdate&);
49
50 #define EVT_SEARCH_UPDATE(fn) \
51         DECLARE_EVENT_TABLE_ENTRY( \
52             wxEVT_SEARCH_UPDATE, -1, -1, \
53             (wxObjectEventFunction)(wxEventFunction)(SearchUpdateFunction)&fn, \
54             (wxObject *)NULL \
55         ),
56
57 class TransmitterSearch : public wxThreadHelper
58 {
59 public:
60     TransmitterSearch(wxEvtHandler *dest);
61     ~TransmitterSearch();
62
63     void Solve(SampleLog *log);
64     bool HasSolution() { return m_log ? m_log->Count() > 1 : false; }
65     void Reset();
66     void ClearStats();
67     bool Busy() const { return m_busy; }
68     int Mode() const { return m_histogram.Mode(); }
69     float Mean() const { return m_histogram.Mean(); }
70     float Concentration() { return m_histogram.Concentration(); }
71
72     const ErrorHistogram &Histogram() { return m_histogram; }
73     Spherical GetEstimatedLocation() { return m_solution; }
74
75     virtual void *Entry();
76                                     
77 private:
78     static const int MaxIterations = 20; // TODO: make configurable
79
80     bool hillclimb(std::vector<Sample> &samples);
81     float calc_trial_error(const std::vector<Sample> &samples, const Spherical &trial, 
82                            float &solution_error);
83
84     void background_solve();
85     void post_update(bool done);
86     
87     // Background processing
88     wxEvtHandler *m_dest;
89     wxMutex m_mutex;
90     wxCondition m_condition;
91     
92     // Solution state
93     SampleLog *m_log;
94     Spherical m_solution;
95     int m_iterations;
96     bool m_initialized;
97     bool m_busy;
98         
99     // Solution options
100     float m_scale;
101     float m_resolution;
102
103     // Estimated solution histogram
104     ErrorHistogram m_histogram;
105 };
106
107 #endif