File: detected_slit.cpp

package info (click to toggle)
cpl-plugin-vimos 3.2.3%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 23,188 kB
  • sloc: ansic: 169,153; cpp: 14,555; sh: 4,250; python: 1,423; makefile: 899; perl: 10
file content (183 lines) | stat: -rw-r--r-- 6,360 bytes parent folder | download | duplicates (5)
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
/* $Id: detected_slit.cpp,v 1.5 2013-08-21 15:13:55 cgarcia Exp $
 *
 * This file is part of the MOSCA library
 * Copyright (C) 2013 European Southern Observatory
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 */

/*
 * $Author: cgarcia $
 * $Date: 2013-08-21 15:13:55 $
 * $Revision: 1.5 $
 * $Name: not supported by cvs2svn $
 */

#include <stdexcept>
#include <iostream>
#include <cmath>
#include "detected_slit.h"

mosca::detected_slit::detected_slit(int slit_ident, 
                                    double disp_bottom, double spa_bottom, 
                                    double disp_top,    double spa_top,
                                    int position_spatial_corrected,
                                    int length_spatial_corrected,
                                    const std::vector<double>& trace_bottom_pol_coeffs,                  
                                    const std::vector<double>& trace_top_pol_coeffs) :
 m_slit_id(slit_ident), m_disp_bottom(disp_bottom),
 m_spa_bottom(spa_bottom), m_disp_top(disp_top), m_spa_top(spa_top),
 m_position_spatial_corrected(position_spatial_corrected),
 m_length_spatial_corrected(length_spatial_corrected),
 m_trace_bottom_pol_coeffs(trace_bottom_pol_coeffs),
 m_trace_top_pol_coeffs(trace_top_pol_coeffs)
{
    
    m_trace_bottom_pol = cpl_polynomial_new(1);
    m_trace_top_pol =  cpl_polynomial_new(1);
    cpl_size idx;
    idx = 0;
    std::vector<double>::reverse_iterator coeff;
    for(idx = trace_bottom_pol_coeffs.size() - 1, coeff = m_trace_bottom_pol_coeffs.rbegin();
            coeff != m_trace_bottom_pol_coeffs.rend(); ++coeff, --idx)
        cpl_polynomial_set_coeff(m_trace_bottom_pol, &idx, *coeff);

    for(idx = trace_top_pol_coeffs.size() -1, coeff = m_trace_top_pol_coeffs.rbegin();
            coeff != m_trace_top_pol_coeffs.rend(); ++coeff, --idx)
        cpl_polynomial_set_coeff(m_trace_top_pol, &idx, *coeff);
}

mosca::detected_slit::detected_slit()
{
    m_slit_id     = 0;
    m_disp_bottom = 0;
    m_spa_bottom  = 0;
    m_disp_top    = 0;
    m_spa_top     = 0;
    m_position_spatial_corrected = 0;
    m_length_spatial_corrected   = 0;
    m_trace_bottom_pol = NULL;
    m_trace_top_pol = NULL;

}

mosca::detected_slit::detected_slit(const detected_slit& rhs)
{
    m_slit_id     = rhs.m_slit_id;
    m_disp_bottom = rhs.m_disp_bottom;
    m_spa_bottom  = rhs.m_spa_bottom;
    m_disp_top    = rhs.m_disp_top;
    m_spa_top     = rhs.m_spa_top;
    m_position_spatial_corrected = rhs.m_position_spatial_corrected;
    m_length_spatial_corrected = rhs.m_length_spatial_corrected;
    m_trace_bottom_pol = cpl_polynomial_duplicate(rhs.m_trace_bottom_pol);
    m_trace_top_pol = cpl_polynomial_duplicate(rhs.m_trace_top_pol);

}

mosca::detected_slit::~detected_slit()
{
    if(m_trace_bottom_pol != NULL)
        cpl_polynomial_delete(m_trace_bottom_pol);
    if(m_trace_top_pol != NULL)
        cpl_polynomial_delete(m_trace_top_pol);
}

void mosca::detected_slit::get_extent(double & disp_bottom, double & spa_bottom, 
                                      double & disp_top,    double & spa_top)
{
    disp_bottom = m_disp_bottom;
    spa_bottom  = m_spa_bottom;
    disp_top    = m_disp_top;
    spa_top     = m_spa_top;
}

void mosca::detected_slit::get_extent_pix(int& disp_bottom, int& spa_bottom, 
                                          int& disp_top,    int& spa_top) const
{
    if(m_disp_bottom < m_disp_top)
    {
        disp_bottom = (int)std::floor(m_disp_bottom);
        disp_top    = (int)std::ceil(m_disp_top);
    }
    else
    {
        disp_bottom = (int)std::ceil(m_disp_bottom);
        disp_top    = (int)std::floor(m_disp_top);

    }
    if(m_spa_bottom < m_spa_top)
    {
        spa_bottom  = (int)std::floor(m_spa_bottom);
        spa_top     = (int)std::ceil(m_spa_top);
    }
    else
    {
        spa_bottom  = (int)std::ceil(m_spa_bottom);
        spa_top     = (int)std::floor(m_spa_top);
    }
}

//TODO:Starting in 0 or 1?
bool mosca::detected_slit::within_trace(double dispersion_pos,
                                        double spatial_pos) const
{
    
    double trace_bottom = cpl_polynomial_eval_1d(m_trace_bottom_pol, 
                                                 dispersion_pos, NULL);
    double trace_top    = cpl_polynomial_eval_1d(m_trace_top_pol, 
                                                 dispersion_pos, NULL);
    
    if(spatial_pos >= trace_bottom && spatial_pos <= trace_top)
        return true;

    return false;
}

double mosca::detected_slit::spatial_correct(double dispersion_pos,
                                             double spatial_pos) const
{
    double trace_bottom = cpl_polynomial_eval_1d(m_trace_bottom_pol, 
                                                 dispersion_pos, NULL);
    double trace_top    = cpl_polynomial_eval_1d(m_trace_top_pol, 
                                                 dispersion_pos, NULL);
    //The -1 factor is there because originally the length of the spatial
    //corrected slit has a +1 added in function mos_spatial_calibration 
    double factor = (trace_top-trace_bottom)/(m_length_spatial_corrected - 1);
    
    double spa_corrected_from_top = (spatial_pos - trace_top) / factor;
    
    double spa_corrected = m_position_spatial_corrected + 
            m_length_spatial_corrected + spa_corrected_from_top;
    
    
    return spa_corrected;
}


int mosca::detected_slit::slit_id() const
{
    return m_slit_id;
}

int mosca::detected_slit::get_position_spatial_corrected() const
{
    return m_position_spatial_corrected;
}

int mosca::detected_slit::get_length_spatial_corrected() const
{
    return m_length_spatial_corrected;
}