1 | #include "machdefs.h"
|
---|
2 | #include <stdlib.h>
|
---|
3 | #include <typeinfo>
|
---|
4 | #include <iostream.h>
|
---|
5 | #include <string>
|
---|
6 |
|
---|
7 | #include "nomspecrespadapter.h"
|
---|
8 | #include "specrespvector.h"
|
---|
9 | #include "gaussfilt.h"
|
---|
10 | #include "pidrawer.h"
|
---|
11 |
|
---|
12 | // ------ Classe de Drawer pour tracer Y = Transmission(nu = X)
|
---|
13 | class PISpectralResponseDrawer : public PIDrawer {
|
---|
14 | public :
|
---|
15 | PISpectralResponseDrawer(SpectralResponse* sr, bool ad=false);
|
---|
16 | ~PISpectralResponseDrawer();
|
---|
17 | virtual void Draw(PIGraphicUC* g, double xmin, double ymin, double xmax, double ymax);
|
---|
18 | virtual void UpdateLimits();
|
---|
19 |
|
---|
20 | protected:
|
---|
21 | SpectralResponse * mSR;
|
---|
22 | bool mAd;
|
---|
23 | };
|
---|
24 |
|
---|
25 | PISpectralResponseDrawer::PISpectralResponseDrawer(SpectralResponse* sr, bool ad)
|
---|
26 | {
|
---|
27 | mSR = sr;
|
---|
28 | mAd = ad;
|
---|
29 | }
|
---|
30 |
|
---|
31 | PISpectralResponseDrawer::~PISpectralResponseDrawer()
|
---|
32 | {
|
---|
33 | if (mAd && mSR) delete mSR;
|
---|
34 | }
|
---|
35 |
|
---|
36 | void
|
---|
37 | PISpectralResponseDrawer::Draw(PIGraphicUC* g, double xmin, double ymin, double xmax, double ymax)
|
---|
38 | {
|
---|
39 | if (!mSR) return;
|
---|
40 | PIGrCoord x1, x2, y1, y2;
|
---|
41 | g->GetGrSpace(x1, x2, y1, y2);
|
---|
42 | double xMax = x2;
|
---|
43 | double xMin = x1;
|
---|
44 | double yMax = y2;
|
---|
45 | double yMin = y1;
|
---|
46 | double xStep = (xMax - xMin)/100;
|
---|
47 | double xOld = xMin;
|
---|
48 | double yOld = mSR->transmission(xMin);
|
---|
49 | double x,y;
|
---|
50 | for (x = xMin+xStep; x<xMax; x+=xStep) {
|
---|
51 | y = mSR->transmission(x);
|
---|
52 | if (y>yMin && yOld>yMin &&
|
---|
53 | y<yMax && yOld<yMax)
|
---|
54 | g->DrawLine(xOld, yOld, x, y);
|
---|
55 | xOld = x;
|
---|
56 | yOld = y;
|
---|
57 | }
|
---|
58 | }
|
---|
59 |
|
---|
60 | void
|
---|
61 | PISpectralResponseDrawer::UpdateLimits()
|
---|
62 | {
|
---|
63 | if (!mSR) return;
|
---|
64 | double xmin, xmax;
|
---|
65 | double ymin, ymax;
|
---|
66 | xmin = mSR->minFreq();
|
---|
67 | xmax = mSR->maxFreq();
|
---|
68 | double dx = (xmax-xmin)*0.025;
|
---|
69 | xmin -= dx; xmax += dx;
|
---|
70 | ymin = 0.;
|
---|
71 | ymax = mSR->peakTransmission()*1.05;
|
---|
72 | SetLimits(xmin, xmax, ymin, ymax);
|
---|
73 | // cout << " DBG - " << xmin << "," << xmax << " " << ymin << "," << ymax << endl;
|
---|
74 | }
|
---|
75 | //-------------------------------------------------------------------------
|
---|
76 | // Class Adaptateur d'objet (Pour NamedObjMgr) d'objet SpectralResponse
|
---|
77 | //-------------------------------------------------------------------------
|
---|
78 |
|
---|
79 | /* --Methode-- */
|
---|
80 | NOMAdapter_SpectralResponse::NOMAdapter_SpectralResponse(SpectralResponse* o)
|
---|
81 | : NObjMgrAdapter(o)
|
---|
82 | {
|
---|
83 | mSR = o;
|
---|
84 | }
|
---|
85 |
|
---|
86 | /* --Methode-- */
|
---|
87 | NOMAdapter_SpectralResponse::~NOMAdapter_SpectralResponse()
|
---|
88 | {
|
---|
89 | }
|
---|
90 |
|
---|
91 | /* --Methode-- */
|
---|
92 | NObjMgrAdapter* NOMAdapter_SpectralResponse::Clone(AnyDataObj* o)
|
---|
93 | {
|
---|
94 | SpectralResponse* sr = dynamic_cast<SpectralResponse *>(o);
|
---|
95 | if (sr) return ( new NOMAdapter_SpectralResponse(sr) );
|
---|
96 | return ( new NObjMgrAdapter(o) );
|
---|
97 | }
|
---|
98 |
|
---|
99 |
|
---|
100 | /* --Methode-- */
|
---|
101 | void NOMAdapter_SpectralResponse::SavePPF(POutPersist& pos, string const & nom)
|
---|
102 | {
|
---|
103 | GaussianFilter* gf = dynamic_cast<GaussianFilter *> (mSR);
|
---|
104 | SpecRespVec* vecFilt = dynamic_cast<SpecRespVec *> (mSR);
|
---|
105 | if (gf) { // C'est un GaussianFilter ....
|
---|
106 | ObjFileIO<GaussianFilter> oio(gf);
|
---|
107 | oio.Write(pos, nom);
|
---|
108 | }
|
---|
109 | else if (vecFilt) {
|
---|
110 | ObjFileIO<SpecRespVec> oio(vecFilt);
|
---|
111 | oio.Write(pos, nom);
|
---|
112 | }
|
---|
113 | else {
|
---|
114 | string s = typeid(*mSR).name();
|
---|
115 | cout << "NOMAdapter_SpectralResponse::SavePPF() - Error : Not supported for " << s << endl;
|
---|
116 | }
|
---|
117 | }
|
---|
118 |
|
---|
119 | /* --Methode-- */
|
---|
120 | void NOMAdapter_SpectralResponse::Print(ostream& os)
|
---|
121 | {
|
---|
122 | os << (*mSR);
|
---|
123 | }
|
---|
124 |
|
---|
125 | /* --Methode-- */
|
---|
126 | PIDrawer* NOMAdapter_SpectralResponse::GetDrawer(string & dopt)
|
---|
127 | {
|
---|
128 | return(new PISpectralResponseDrawer(mSR, false));
|
---|
129 | }
|
---|
130 |
|
---|
131 |
|
---|
132 | /* --Methode--
|
---|
133 | NTupleInterface* NOMAdapter_SpectralResponse::GetNTupleInterface(bool& adel)
|
---|
134 | {
|
---|
135 | adel = true;
|
---|
136 | return( new NTupInt_SpectralResponse(mSR) );
|
---|
137 | }
|
---|
138 | */
|
---|
139 |
|
---|
140 |
|
---|