General Purpose Geodetic Library
NsTestDialog.cpp
Go to the documentation of this file.
1 /*
2  *
3  * This file is a part of nuSolve. nuSolve is a part of CALC/SOLVE system
4  * and is designed to perform data analyis of a geodetic VLBI session.
5  * Copyright (C) 2010-2020 Sergei Bolotin.
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 #include "nuSolve.h"
23 #include "NsTestDialog.h"
24 
25 #include <iostream>
26 #include <stdlib.h>
27 
28 
29 #include <SgCubicSpline.h>
30 #include <SgGuiPlotter.h>
31 #include <SgLogger.h>
32 #include <SgMJD.h>
33 
34 #if QT_VERSION >= 0x050000
35 # include <QtWidgets/QLabel>
36 # include <QtWidgets/QGroupBox>
37 # include <QtWidgets/QBoxLayout>
38 # include <QtWidgets/QPushButton>
39 # include <QtWidgets/QFrame>
40 #else
41 # include <QtGui/QLabel>
42 # include <QtGui/QGroupBox>
43 # include <QtGui/QBoxLayout>
44 # include <QtGui/QPushButton>
45 # include <QtGui/QFrame>
46 #endif
47 
48 
49 
50 /*=======================================================================================================
51 *
52 * METHODS:
53 *
54 *======================================================================================================*/
55 NsTestDialog::NsTestDialog(QWidget *parent, Qt::WindowFlags flags)
56  : QDialog(parent, flags)
57 {
58  QBoxLayout *Layout, *SubLayout;
59  QSize BtnSize;
60 
61  Layout = new QVBoxLayout(this);
62  Layout->addWidget(testPlot(), 10);
63  SubLayout = new QHBoxLayout();
64  Layout->addLayout(SubLayout);
65  SubLayout->addStretch(1);
66 
67  QPushButton *Ok=new QPushButton("OK", this);
68  QPushButton *Cancel=new QPushButton("Cancel", this);
69  Ok->setDefault(true);
70 
71  Cancel->setMinimumSize((BtnSize=Cancel->sizeHint()));
72  Ok ->setMinimumSize(BtnSize);
73 
74  SubLayout->addWidget(Ok);
75  SubLayout->addWidget(Cancel);
76 
77  connect(Ok, SIGNAL(clicked()), SLOT(accept()));
78  connect(Cancel, SIGNAL(clicked()), SLOT(reject()));
79  setWindowTitle("Test Dialog");
80 };
81 
82 
83 
85 {
86  if (carrier_)
87  {
88  delete carrier_;
89  carrier_ = NULL;
90  }
91 };
92 
93 
94 
96 {
97  QDialog::accept();
99  ": accept selected");
100  deleteLater();
101 };
102 
103 
104 
106 {
107  QDialog::reject();
109  ": reject selected");
110  deleteLater();
111 };
112 
113 
114 
115 
117 {
118  int numOfVals = 4;
119  int numOfSigs = 2;
120  int numOfBranches = 3;
121  int numsOfRows[3] = {20, 45, 57};
122  int numOfSpl = 500;
123  const char* branchNames[3] = {"Branch #1", "Branch #2", "Branch #3"};
124 
125  carrier_ = new SgPlotCarrier(numOfVals, numOfSigs, "Plot testing");
126 
127  for (int i=0; i<numOfBranches; i++)
128  carrier_->createBranch(numsOfRows[i], branchNames[i]);
129 
130  carrier_->createBranch(numOfSpl, "Cubic Spline #2");
131 
132  carrier_->setNameOfColumn(0, "Time, MJD");
134  carrier_->setNameOfColumn(1, "Value #1");
135  carrier_->setNameOfColumn(2, "Value #2");
136  carrier_->setNameOfColumn(3, "Value #3");
137  carrier_->setNameOfColumn(4, "Sigma #1");
138  carrier_->setNameOfColumn(5, "Sigma #2");
139 
140  carrier_->setStdVarIdx( 1, 4);
141  carrier_->setStdVarIdx( 2, 5);
142 
143 
144  double t0=tEphem.getDate()-10.2, dt=0.1;
145  double tShifts[3] = {2.33, -1.8, 1.16};
146  double dPeriods[3] = {-0.8, 0.3, 1.1};
147  double dPhases[3] = {-3.8, 2.3, 4.7};
148  double dAmplitudes[3] = {-1.3, 2.8, 0.7};
149  for (int i =0; i<numOfBranches; i++)
150  {
151  SgPlotBranch* branch = carrier_->listOfBranches()->at(i);
152  double t = t0 + tShifts[i];
153  double a, b, c;
154  double ae, be;
155  for (int j=0; j<numsOfRows[i]; j++)
156  {
157  t += dt;
158 
159  a = 8.0 + dPhases[i] + (3.0 + dAmplitudes[i])*
160  cos(2.0*M_PI/(7.0 + dPeriods[i])*(t - tEphem + 4.5 + dPhases[i])) +
161  2.5*dAmplitudes[i]*(((double)random())/RAND_MAX - 0.5);
162 
163 
164  b = 2.0 + tShifts[i] + (0.8 + dAmplitudes[i])*
165  cos(2.0*M_PI/(3.5 + dPeriods[i])*(t - tEphem - 2.3 + dPhases[i])) +
166  1.2*dAmplitudes[i]*(((double)random())/RAND_MAX - 0.5);
167 
168  c = 18.0 - 6.3*(t - tEphem + dPhases[i]) +
169  4.2*dAmplitudes[i]*(t - tEphem + dPhases[i])/(2.25 +
170  1.0*sin(2.0*M_PI/(2.3 + dPeriods[i])*(t - tEphem + dPhases[i])));
171 
172  ae = 4.0 + 3.3*sin(2.0*M_PI/3.0*(t-tEphem + 3.3));
173  be = 1.5 + 1.0*sin(2.0*M_PI/7.0*(t-tEphem));
174  branch->data()->setElement(j, 0, t);
175  branch->data()->setElement(j, 1, a);
176  branch->data()->setElement(j, 2, b);
177  branch->data()->setElement(j, 3, c);
178  branch->data()->setElement(j, 4, ae);
179  branch->data()->setElement(j, 5, be);
180  };
181  };
182  // an example how to use splines:
183  // prepare splines:
184  SgPlotBranch *workBranch = carrier_->listOfBranches()->at(1);
185  SgPlotBranch *splineValBranch = carrier_->listOfBranches()->at(numOfBranches);
186  int nRows=workBranch->data()->nRow();
187  // create the spline object:
188  SgCubicSpline spliner(nRows, 5);
189  // feed it:
190  for (int i=0; i<nRows; i++)
191  {
192  spliner.argument().setElement(i, workBranch->data()->getElement(i, 0));
193  spliner.table().setElement(i, 0, workBranch->data()->getElement(i, 1));
194  spliner.table().setElement(i, 1, workBranch->data()->getElement(i, 2));
195  spliner.table().setElement(i, 2, workBranch->data()->getElement(i, 3));
196  spliner.table().setElement(i, 3, workBranch->data()->getElement(i, 4));
197  spliner.table().setElement(i, 4, workBranch->data()->getElement(i, 5));
198  };
199  // evaluate spline coefficients:
200  spliner.prepare4Spline();
201  // add splines to the plot:
202  double t, r;
203  t = spliner.argument().getElement(0);
204  dt = (spliner.argument().getElement(nRows-1) - spliner.argument().getElement(0))/(numOfSpl - 1);
205  // use splines:
206  for (int i=0; i<numOfSpl; i++)
207  {
208  splineValBranch->data()->setElement(i, 0, t);
209  splineValBranch->data()->setElement(i, 1, spliner.spline(t, 0, r));
210  splineValBranch->data()->setElement(i, 2, spliner.spline(t, 1, r));
211  splineValBranch->data()->setElement(i, 3, spliner.spline(t, 2, r));
212  splineValBranch->data()->setElement(i, 4, spliner.spline(t, 3, r));
213  splineValBranch->data()->setElement(i, 5, spliner.spline(t, 4, r));
214  t += dt;
215  };
218  return plot_;
219 };
220 /*=====================================================================================================*/
SgLogger * logger
Definition: SgLogger.cpp:231
const SgMJD tEphem(51544.5)
SgPlot::OutputFormat getPlotterOutputFormat() const
Definition: NsSetup.h:654
const QString & getPath2PlotterOutput() const
Definition: NsSetup.h:486
QString className() const
Definition: NsTestDialog.h:73
virtual ~NsTestDialog()
SgPlotCarrier * carrier_
Definition: NsTestDialog.h:95
SgPlot * plot_
Definition: NsTestDialog.h:96
NsTestDialog(QWidget *parent=0, Qt::WindowFlags flags=0)
QWidget * testPlot()
void prepare4Spline()
SgMatrix & table()
double spline(double arg, int nColumn, double &r)
SgVector & argument()
virtual void write(LogLevel, quint32, const QString &, bool=false)
Definition: SgLogger.cpp:88
int getDate() const
Definition: SgMJD.h:449
unsigned int nRow() const
Definition: SgMatrix.h:352
void setElement(unsigned int i, unsigned int j, double d)
Definition: SgMatrix.h:402
double getElement(unsigned int i, unsigned int j) const
Definition: SgMatrix.h:385
SgMatrix * data()
Definition: SgGuiPlotter.h:83
void createBranch(unsigned int numberOfRows, const QString &branchName, bool hasExtKeys=false)
QList< SgPlotBranch * > * listOfBranches()
Definition: SgGuiPlotter.h:163
void setNameOfColumn(unsigned int, const QString &)
void setAxisType(int columnIdx, AxisType axisType)
Definition: SgGuiPlotter.h:207
void setStdVarIdx(int columnIdx, int sigmaColumnIdx)
Definition: SgGuiPlotter.h:216
void setOutputFormat(OutputFormat fmt)
Definition: SgGuiPlotter.h:625
void setElement(unsigned int i, double d)
Definition: SgVector.h:348
double getElement(unsigned int i) const
Definition: SgVector.h:362
NsSetup setup
Definition: nuSolve.cpp:61