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

Last change on this file since 3558 was 2975, checked in by ansari, 19 years ago

Ajout flag int lev ds les adaptateurs NObjMgrAdapter::Print(ostream& os, int lev=0) et NamedObjMgr::Print() + modif commande print - Reza 20 Juin 2006

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