1 | // This may look like C code, but it is really -*- C++ -*-
|
---|
2 | // classe pour tracer des flow chart (champs de vecteurs) 2d
|
---|
3 | // NB herite de PIDrawer
|
---|
4 | // O. Perdereau 01/2002
|
---|
5 | //
|
---|
6 | // LAL (Orsay) / IN2P3-CNRS DAPNIA/SPP (Saclay) / CEA
|
---|
7 |
|
---|
8 | #include "sopnamsp.h"
|
---|
9 | #include "machdefs.h"
|
---|
10 | #include <stdio.h>
|
---|
11 | #include <stdlib.h>
|
---|
12 | #include <iostream>
|
---|
13 | #include <math.h>
|
---|
14 |
|
---|
15 | #include "histos.h"
|
---|
16 | #include "ntuple.h"
|
---|
17 |
|
---|
18 | #include "nbtri.h"
|
---|
19 |
|
---|
20 | #include "pi2dvec.h"
|
---|
21 |
|
---|
22 | #include <sys/time.h>
|
---|
23 | #include <sys/resource.h>
|
---|
24 |
|
---|
25 | //++
|
---|
26 | // Class PI2dVecDrawer
|
---|
27 | // Lib PIGcont
|
---|
28 | // include pigncont.h2dvec.h
|
---|
29 | //
|
---|
30 | //
|
---|
31 | // Classe de trace d'un champ de vecteurs (flow chart) en 2 dimensions
|
---|
32 | //
|
---|
33 | //
|
---|
34 | //--
|
---|
35 | //++
|
---|
36 | // Links Parents
|
---|
37 | // PIDrawer
|
---|
38 | //--
|
---|
39 | //
|
---|
40 | //++
|
---|
41 | // Titre Constructeurs et Méthodes
|
---|
42 | //--
|
---|
43 |
|
---|
44 | //++
|
---|
45 | // PI2dVecDrawer::PI2dVecDrawer(NTupleInterface* nti,bool autodel)
|
---|
46 | // Constructeur
|
---|
47 | //
|
---|
48 | //--
|
---|
49 | PI2dVecDrawer::PI2dVecDrawer(NTupleInterface* nti,bool autodel)
|
---|
50 | {
|
---|
51 | _nti = nti;
|
---|
52 |
|
---|
53 | _autodel = autodel;
|
---|
54 | SelectXY(NULL, NULL);
|
---|
55 | SelectVW(NULL, NULL);
|
---|
56 |
|
---|
57 | // This drawer has *NO* specific control tools
|
---|
58 | mFgSpecContWind = false;
|
---|
59 |
|
---|
60 | }
|
---|
61 |
|
---|
62 |
|
---|
63 | /* --Methode-- */
|
---|
64 | PI2dVecDrawer::~PI2dVecDrawer()
|
---|
65 | {
|
---|
66 |
|
---|
67 | if(_autodel){ //cout << " destructeur de PI2dVecDrawer / autodel "<<endl;
|
---|
68 | if(_nti!=NULL){delete _nti ; _nti=NULL;}
|
---|
69 | }
|
---|
70 |
|
---|
71 | }
|
---|
72 |
|
---|
73 | /* --Methode-- */
|
---|
74 | void PI2dVecDrawer::Draw(PIGraphicUC* g, double xmin, double ymin, double xmax, double ymax){
|
---|
75 |
|
---|
76 | if(_nti==NULL){cout << " PI2dVecDrawer::Draw : null ntuple "<<endl; return;}
|
---|
77 | if ( (xK < 0) || (yK < 0) ){cout << " PI2dVecDrawer::Draw : no X/Y "<<endl; return;}
|
---|
78 | if ( (vK < 0) || (wK < 0) ){cout << " PI2dVecDrawer::Draw : no VX/VY "<<endl; return;}
|
---|
79 |
|
---|
80 | int npt = _nti->NbLines();
|
---|
81 | int i=0;
|
---|
82 | double x,y,vx,vy;
|
---|
83 | double xa[2];
|
---|
84 | double ya[2];
|
---|
85 | g->SaveGraphicAtt();
|
---|
86 |
|
---|
87 | // choix de la couleur
|
---|
88 | g->SelForeground(GetGraphicAtt().GetFgColor());
|
---|
89 |
|
---|
90 | // choix de la ligne
|
---|
91 | PILineAtt mlatt = GetGraphicAtt().GetLineAtt() ;
|
---|
92 | if(mlatt==PI_NotDefLineAtt) GetGraphicAtt().SetLineAtt(PI_NormalLine);
|
---|
93 |
|
---|
94 | g->SelLine(GetGraphicAtt().GetLineAtt() );
|
---|
95 |
|
---|
96 | // choix du marker
|
---|
97 | if(GetGraphicAtt().GetMarker()==PI_NotDefMarker)
|
---|
98 | GetGraphicAtt().SetMarkerAtt(5,PI_FCircleMarker);
|
---|
99 | g->SelMarker(GetGraphicAtt().GetMarkerSize(),GetGraphicAtt().GetMarker());
|
---|
100 |
|
---|
101 | // choix de la fleche
|
---|
102 |
|
---|
103 | if(GetGraphicAtt().GetArrowMarker()==PI_NotDefArrowMarker)
|
---|
104 | GetGraphicAtt().SetArrowMarkerAtt(5,PI_BasicArrowMarker);
|
---|
105 |
|
---|
106 |
|
---|
107 |
|
---|
108 | g->SelArrowMarker(GetGraphicAtt().GetArrowMarkerSize(),GetGraphicAtt().GetArrowMarker());
|
---|
109 |
|
---|
110 |
|
---|
111 |
|
---|
112 | for(i=0 ; i<npt ; i++){
|
---|
113 | x = _nti->GetCell(i,xK) ;
|
---|
114 | y = _nti->GetCell(i,yK) ;
|
---|
115 | vx = _nti->GetCell(i,vK) + x;
|
---|
116 | vy = _nti->GetCell(i,wK) + y;
|
---|
117 | g->DrawMarker(x,y);
|
---|
118 |
|
---|
119 | //g->DrawLine(x,y,vx,vy);
|
---|
120 |
|
---|
121 | g->DrawArrowMarker(x,y,vx,vy);
|
---|
122 |
|
---|
123 | }
|
---|
124 |
|
---|
125 | g->RestoreGraphicAtt();
|
---|
126 |
|
---|
127 | }
|
---|
128 | /* --Methode-- */
|
---|
129 | void PI2dVecDrawer::UpdateLimits()
|
---|
130 | {
|
---|
131 | // Doit calculer les limites
|
---|
132 |
|
---|
133 | double xmn,xmx,ymn,ymx;
|
---|
134 | double vmn,vmx;
|
---|
135 |
|
---|
136 | _nti->GetMinMax(0,xmn,xmx);
|
---|
137 | _nti->GetMinMax(1,ymn,ymx);
|
---|
138 |
|
---|
139 | SetLimits(xmn, xmx, ymn, ymx);
|
---|
140 | }
|
---|
141 |
|
---|
142 | /* --Methode-- */
|
---|
143 | int PI2dVecDrawer::SelectXY(const char* px, const char* py)
|
---|
144 | {
|
---|
145 | string name;
|
---|
146 | if (_nti == NULL) xK = yK = -1;
|
---|
147 | if (px == NULL) xK = -1;
|
---|
148 | else { name = px; xK = _nti->ColumnIndex(name); }
|
---|
149 | if (py == NULL) yK = -1;
|
---|
150 | else { name = py; yK = _nti->ColumnIndex(name); }
|
---|
151 |
|
---|
152 | int ret = xK;
|
---|
153 | if( ret > yK) ret = yK;
|
---|
154 | return(ret);
|
---|
155 | }
|
---|
156 |
|
---|
157 | /* --Methode-- */
|
---|
158 | int PI2dVecDrawer::SelectVW(const char* px, const char* py)
|
---|
159 | {
|
---|
160 | string name;
|
---|
161 | if (_nti == NULL) vK = vK = -1;
|
---|
162 | if (px == NULL) vK = -1;
|
---|
163 | else { name = px; vK = _nti->ColumnIndex(name); }
|
---|
164 | if (py == NULL) wK = -1;
|
---|
165 | else { name = py; wK = _nti->ColumnIndex(name); }
|
---|
166 |
|
---|
167 | int ret = vK;
|
---|
168 | if( ret > wK) ret = wK;
|
---|
169 | return(ret);
|
---|
170 | }
|
---|
171 |
|
---|
172 |
|
---|
173 |
|
---|
174 | /* --Methode-- */
|
---|
175 | double PI2dVecDrawer::GetDistanceToPoint(double x, double y)
|
---|
176 | {
|
---|
177 | if(_nti==NULL) return 1.e+9;
|
---|
178 | if( xK<0 || yK<0 ) return 1.e+9;
|
---|
179 | if( vK<0 || wK<0 ) return 1.e+9;
|
---|
180 |
|
---|
181 | double dist = -1.e+18;
|
---|
182 | for(int i=0; i<_nti->NbLines(); i++) {
|
---|
183 | double xp=_nti->GetCell(i,xK);
|
---|
184 | double yp=_nti->GetCell(i,yK);
|
---|
185 | xp = (xp-x)/(XMax()-XMin())/0.5;
|
---|
186 | yp = (yp-y)/(YMax()-YMin())/0.5;
|
---|
187 | xp = xp*xp+yp*yp;
|
---|
188 | if(dist<0. || xp<dist) dist = xp;
|
---|
189 | }
|
---|
190 | dist=sqrt(fabs(dist));
|
---|
191 | cout<<dist<<"PI2dVecDrawer: xlim="<<XMin()<<","<<XMax()<<" ylim="<<YMin()<<","<<YMax()
|
---|
192 | <<" NbLines="<<_nti->NbLines()<<endl;
|
---|
193 | cout<<"....d="<<dist<<" x="<<x<<" y="<<y<<endl;
|
---|
194 | cout<<"****** NON teste (CMV) ******"<<endl;
|
---|
195 |
|
---|
196 | return dist;
|
---|
197 | }
|
---|