source: Sophya/trunk/SophyaPI/PIext/nomspecrespadapter.cc@ 2089

Last change on this file since 2089 was 670, checked in by ercodmgr, 26 years ago

Ajout Adaptateur pour SpectralResponse , Sophie 29/11/99

File size: 3.4 KB
RevLine 
[670]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)
13class PISpectralResponseDrawer : public PIDrawer {
14public :
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
20protected:
21SpectralResponse * mSR;
22bool mAd;
23};
24
25PISpectralResponseDrawer::PISpectralResponseDrawer(SpectralResponse* sr, bool ad)
26{
27mSR = sr;
28mAd = ad;
29}
30
31PISpectralResponseDrawer::~PISpectralResponseDrawer()
32{
33if (mAd && mSR) delete mSR;
34}
35
36void
37PISpectralResponseDrawer::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
60void
61PISpectralResponseDrawer::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-- */
80NOMAdapter_SpectralResponse::NOMAdapter_SpectralResponse(SpectralResponse* o)
81 : NObjMgrAdapter(o)
82{
83mSR = o;
84}
85
86/* --Methode-- */
87NOMAdapter_SpectralResponse::~NOMAdapter_SpectralResponse()
88{
89}
90
91/* --Methode-- */
92NObjMgrAdapter* NOMAdapter_SpectralResponse::Clone(AnyDataObj* o)
93{
94SpectralResponse* sr = dynamic_cast<SpectralResponse *>(o);
95if (sr) return ( new NOMAdapter_SpectralResponse(sr) );
96return ( new NObjMgrAdapter(o) );
97}
98
99
100/* --Methode-- */
101void 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-- */
120void NOMAdapter_SpectralResponse::Print(ostream& os)
121{
122os << (*mSR);
123}
124
125/* --Methode-- */
126PIDrawer* NOMAdapter_SpectralResponse::GetDrawer(string & dopt)
127{
128return(new PISpectralResponseDrawer(mSR, false));
129}
130
131
132/* --Methode--
133NTupleInterface* NOMAdapter_SpectralResponse::GetNTupleInterface(bool& adel)
134{
135adel = true;
136return( new NTupInt_SpectralResponse(mSR) );
137}
138*/
139
140
Note: See TracBrowser for help on using the repository browser.