MultiDataPlot.h
1//-*-C++-*-
2/***************************************************************************
3 *
4 * Copyright (C) 2020 by Willem van Straten
5 * Licensed under the Academic Free License version 2.1
6 *
7 ***************************************************************************/
8
9// psrchive/More/Plotting/Pulsar/MultiDataPlot.h
10
11#ifndef __Pulsar_MultiDataPlot_h
12#define __Pulsar_MultiDataPlot_h
13
14#include "Pulsar/MultiData.h"
15
16#include "Pulsar/SimplePlot.h"
17#include "Pulsar/PlotFrame.h"
18#include "Pulsar/MultiFrame.h"
19#include "Pulsar/Archive.h"
20
21#include <iostream>
22using namespace std;
23
24namespace Pulsar {
25
27 template<class Type> class MultiDataPlot : public MultiData
28 {
29
30 public:
31
33 MultiDataPlot (Type* simple = 0);
34
36 void manage (Type*);
37
39 void plot (const Archive*);
40
42 void finalize ();
43
44 protected:
45
46 Reference::To<Type> the_plot;
47
48 std::vector< Reference::To<Type> > plots;
49 std::vector< Reference::To<const Archive> > data_sets;
50
51 };
52
53}
54
56template<class Type>
58{
59 manage (simple);
60}
61
63template<class Type>
65{
66 managed_plot = simple;
67 the_plot = simple;
68}
69
71template<class Type>
73{
74 the_plot->get_frame()->init (data);
75
76 if (verbose)
77 cerr << "MultiDataPlot<Type>::plot call Type::prepare" << endl;
78
79 the_plot->prepare (data);
80
81 if (verbose)
82 cerr << "MultiDataPlot<Type>::plot ptr=" << the_plot.ptr() << endl;
83
84 plots.push_back (the_plot);
85 data_sets.push_back (data);
86
87 Reference::To<Plot> like = the_plot->get_constructor()->construct();
88 Type* new_plot = dynamic_cast<Type*> (like.ptr());
89
90 if (!new_plot)
91 throw Error (InvalidState, "Pulsar::MultiDataPlot<Type>::plot",
92 "Plot::Constructor::construct does not return a Type");
93
94 // configure new_plot using the saved options
95 for (unsigned i=0; i<options.size(); i++)
96 {
97 if (verbose)
98 cerr << "Pulsar::MultiDataPlot<Type>::plot apply "
99 "'" << options[i] << "'" << endl;
100 new_plot->configure( options[i] );
101 }
102
103 // then replace the_plot with new_plot
104 manage (new_plot);
105}
106
107template<class Type>
109{
110 if (verbose)
111 cerr << "Pulsar::MultiDataPlot<Type>::finalize" << endl;
112
113 if (!data_sets.size())
114 return;
115
116 Type* main_plot = plots[0];
117
118 for (unsigned i=1; i < plots.size(); i++)
119 main_plot->get_frame()->include( plots[i]->get_frame() );
120
121 for (unsigned i=0; i < plots.size(); i++)
122 {
123 plots[i]->get_frame()->copy( main_plot->get_frame() );
124 plots[i]->get_frame()->freeze();
125 }
126
127 for (unsigned i=0; i < plots.size(); i++)
128 plots[i]->plot( data_sets[i] );
129
130 plots.resize(0);
131 data_sets.resize(0);
132}
133
134
135#endif
136
The primary interface to pulsar observational data.
Definition Archive.h:46
MultiDataPlot(Type *simple=0)
Construct with plot to be managed.
Definition MultiDataPlot.h:57
void plot(const Archive *)
prepare the Simple Plot and push it onto the plots vector
Definition MultiDataPlot.h:72
void finalize()
draw the accumulated plots
Definition MultiDataPlot.h:108
void manage(Type *)
Manage a plot.
Definition MultiDataPlot.h:64
Combines multiple data sets in a single plot.
Definition MultiData.h:20
Reference::To< Plot > managed_plot
The plot that is managed by this instance.
Definition MultiData.h:57
std::vector< std::string > options
The options passed to configure.
Definition MultiData.h:60
static bool verbose
Verbosity flag.
Definition Plot.h:28
const Type * ptr() const
Defines the PSRCHIVE library.
Definition CalSource.h:17
STL namespace.

Generated using doxygen 1.14.0