1 /*
2  *  star.h
3  *  PHD Guiding
4  *
5  *  Created by Craig Stark.
6  *  Refactored by Bret McKee
7  *  Copyright (c) 2006-2010 Craig Stark.
8  *  Copyright (c) 2012 Bret McKee
9  *  All rights reserved.
10  *
11  *  This source code is distributed under the following "BSD" license
12  *  Redistribution and use in source and binary forms, with or without
13  *  modification, are permitted provided that the following conditions are met:
14  *    Redistributions of source code must retain the above copyright notice,
15  *     this list of conditions and the following disclaimer.
16  *    Redistributions in binary form must reproduce the above copyright notice,
17  *     this list of conditions and the following disclaimer in the
18  *     documentation and/or other materials provided with the distribution.
19  *    Neither the name of Bret McKee, Dad Dog Development,
20  *     Craig Stark, Stark Labs nor the names of its
21  *     contributors may be used to endorse or promote products derived from
22  *     this software without specific prior written permission.
23  *
24  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
25  *  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26  *  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27  *  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
28  *  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
29  *  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
30  *  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
31  *  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
32  *  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
33  *  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34  *  POSSIBILITY OF SUCH DAMAGE.
35  *
36  */
37 
38 #ifndef STAR_H_INCLUDED
39 #define STAR_H_INCLUDED
40 
41 #include "point.h"
42 
43 class Star : public PHD_Point
44 {
45 public:
46     enum FindMode
47     {
48         FIND_CENTROID,
49         FIND_PEAK,
50     };
51 
52     enum FindResult
53     {
54         STAR_OK = 0,
55         STAR_SATURATED,
56         STAR_LOWSNR,
57         STAR_LOWMASS,
58         STAR_LOWHFD,
59         STAR_TOO_NEAR_EDGE,
60         STAR_MASSCHANGE,
61         STAR_ERROR,
62     };
63 
64     double Mass;
65     double SNR;
66     double HFD;
67     unsigned short PeakVal;
68 
69     Star();
70 
71     /*
72      * Note: contrary to most boolean PHD functions, the star find functions return
73      *       a boolean indicating success instead of a boolean indicating an
74      *       error
75      */
76     bool Find(const usImage *pImg, int searchRegion, FindMode mode, double min_hfd, unsigned short saturation);
77     bool Find(const usImage *pImg, int searchRegion, int X, int Y, FindMode mode, double min_hfd, unsigned short saturation);
78 
79     static bool WasFound(FindResult result);
80     bool WasFound() const;
81     void Invalidate();
82     void SetError(FindResult error);
83     FindResult GetError() const;
84 
85 private:
86     FindResult m_lastFindResult;
87 };
88 
GetError()89 inline Star::FindResult Star::GetError() const
90 {
91     return m_lastFindResult;
92 }
93 
94 class GuideStar : public Star
95 {
96 public:
97     PHD_Point referencePoint;
98     unsigned int missCount;
99     unsigned int zeroCount;
100     unsigned int lostCount;
101 
GuideStar()102     GuideStar()
103         :
104         referencePoint(0., 0.),
105         missCount(0),
106         zeroCount(0),
107         lostCount(0)
108     {
109     }
110 
GuideStar(const Star & star)111     GuideStar(const Star& star)
112         :
113         Star(star),
114         referencePoint(star),
115         missCount(0),
116         zeroCount(0),
117         lostCount(0)
118     {
119     }
120 
121     bool AutoFind(const usImage& image, int extraEdgeAllowance, int searchRegion, const wxRect& roi,
122         std::vector<GuideStar>& foundStars, int maxStars);
123 };
124 
125 #endif /* STAR_H_INCLUDED */
126