File: BasicMathPlugin.h

package info (click to toggle)
indi 2.1.9%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 15,888 kB
  • sloc: cpp: 217,447; ansic: 31,363; xml: 1,195; sh: 311; makefile: 13
file content (109 lines) | stat: -rw-r--r-- 5,231 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
/// \file BasicMathPlugin.h
///
/// \author Roger James
/// \date 13th November 2013
///
/// This file provides the common functionality for the built in
/// and SVD math plugins

#pragma once

#include "AlignmentSubsystemForMathPlugins.h"
#include "ConvexHull.h"

#include <gsl/gsl_matrix.h>

namespace INDI
{
namespace AlignmentSubsystem
{
/// \class BasicMathPlugin
/// \brief This class implements the common functionality for the built in
/// and SVD math plugins
class BasicMathPlugin : public AlignmentSubsystemForMathPlugins
{
    public:
        /// \brief Default constructor
        BasicMathPlugin();

        /// \brief Virtual destructor
        virtual ~BasicMathPlugin();

        /// \brief Override for the base class virtual function
        virtual bool Initialise(InMemoryDatabase *pInMemoryDatabase);

        /// \brief Override for the base class virtual function
        virtual bool TransformCelestialToTelescope(const double RightAscension, const double Declination,
                double JulianOffset,
                TelescopeDirectionVector &ApparentTelescopeDirectionVector);

        /// \brief Override for the base class virtual function
        virtual bool TransformTelescopeToCelestial(const TelescopeDirectionVector &ApparentTelescopeDirectionVector,
                double &RightAscension, double &Declination);

    protected:
        /// \brief Calculate transformation matrices from the supplied vectors
        /// \param[in] Alpha1 Pointer to the first coordinate in the alpha reference frame
        /// \param[in] Alpha2 Pointer to the second coordinate in the alpha reference frame
        /// \param[in] Alpha3 Pointer to the third coordinate in the alpha reference frame
        /// \param[in] Beta1 Pointer to the first coordinate in the beta reference frame
        /// \param[in] Beta2 Pointer to the second coordinate in the beta reference frame
        /// \param[in] Beta3 Pointer to the third coordinate in the beta reference frame
        /// \param[in] pAlphaToBeta Pointer to a matrix to receive the Alpha to Beta transformation matrix
        /// \param[in] pBetaToAlpha Pointer to a matrix to receive the Beta to Alpha transformation matrix
        virtual void
        CalculateTransformMatrices(const TelescopeDirectionVector &Alpha1, const TelescopeDirectionVector &Alpha2,
                                   const TelescopeDirectionVector &Alpha3, const TelescopeDirectionVector &Beta1,
                                   const TelescopeDirectionVector &Beta2, const TelescopeDirectionVector &Beta3,
                                   gsl_matrix *pAlphaToBeta, gsl_matrix *pBetaToAlpha) = 0;

        /// \brief Print out a 3 vector to debug
        /// \param[in] Label A label to identify the vector
        /// \param[in] pVector The vector to print
        void Dump3(const char *Label, gsl_vector *pVector);

        /// \brief Print out a 3x3 matrix to debug
        /// \param[in] Label A label to identify the matrix
        /// \param[in] pMatrix The matrix to print
        void Dump3x3(const char *Label, gsl_matrix *pMatrix);

        /// \brief Calculate the determinant of the supplied matrix
        /// \param[in] pMatrix Pointer to the 3x3 matrix
        /// \return The determinant
        double Matrix3x3Determinant(gsl_matrix *pMatrix);

        /// \brief Calculate the inverse of the supplied matrix
        /// \param[in] pInput Pointer to the input matrix
        /// \param[in] pInversion Pointer to a matrix to receive the inversion
        /// \return False if input matrix is singular (not invertable) otherwise true
        bool MatrixInvert3x3(gsl_matrix *pInput, gsl_matrix *pInversion);

        /// \brief Multiply matrix A by matrix B and put the result in C
        void MatrixMatrixMultiply(gsl_matrix *pA, gsl_matrix *pB, gsl_matrix *pC);

        /// \brief Multiply matrix A by vector B and put the result in vector C
        void MatrixVectorMultiply(gsl_matrix *pA, gsl_vector *pB, gsl_vector *pC);

        /// \brief Test if a ray intersects a triangle in 3d space
        /// \param[in] Ray The ray vector
        /// \param[in] TriangleVertex1 The first vertex of the triangle
        /// \param[in] TriangleVertex2 The second vertex of the triangle
        /// \param[in] TriangleVertex3 The third vertex of the triangle
        /// \note The order of the vertices determine whether the triangle is facing away from or towards the origin.
        /// Intersection with triangles facing the origin will be ignored.
        bool RayTriangleIntersection(TelescopeDirectionVector &Ray, TelescopeDirectionVector &TriangleVertex1,
                                     TelescopeDirectionVector &TriangleVertex2, TelescopeDirectionVector &TriangleVertex3);

        // Transformation matrixes for 1, 2 and 3 sync points case
        gsl_matrix *pActualToApparentTransform;
        gsl_matrix *pApparentToActualTransform;

        // Convex hulls for 4+ sync points case
        ConvexHull ActualConvexHull;
        ConvexHull ApparentConvexHull;
        // Actual direction cosines for the 4+ case
        std::vector<TelescopeDirectionVector> ActualDirectionCosines;
};

} // namespace AlignmentSubsystem
} // namespace INDI