00001
00002
00003 #include <cmath>
00004 #include <iostream>
00005
00006
00007 #include "TAxis.h"
00008
00009
00010 #include "DrawSpan.h"
00011
00012 using namespace std;
00013
00014
00015 Anp::DrawSpan::DrawSpan()
00016 :fInitU(false),
00017 fInitV(false),
00018 fInitZ(false),
00019 fInitTime(false),
00020 fMinU(0.0),
00021 fMaxU(0.0),
00022 fMinV(0.0),
00023 fMaxV(0.0),
00024 fMinZ(0.0),
00025 fMaxZ(0.0),
00026 fMinTime(0.0),
00027 fMaxTime(0.0)
00028 {
00029 }
00030
00031
00032 void Anp::DrawSpan::Reset()
00033 {
00034 fInitU = false;
00035 fInitV = false;
00036 fInitZ = false;
00037 fInitTime = false;
00038
00039 fMinU = 0.0;
00040 fMaxU = 0.0;
00041
00042 fMinV = 0.0;
00043 fMaxV = 0.0;
00044
00045 fMinZ = 0.0;
00046 fMaxZ = 0.0;
00047
00048 fMinTime = 0.0;
00049 fMaxTime = 0.0;
00050 }
00051
00052
00053 float Anp::DrawSpan::GetMinU(const float scale, const float border) const
00054 {
00055 return Min(fMinU, scale) - border;
00056 }
00057
00058
00059 float Anp::DrawSpan::GetMaxU(const float scale, const float border) const
00060 {
00061 return Max(fMaxU, scale) + border;
00062 }
00063
00064
00065 float Anp::DrawSpan::GetMinV(const float scale, const float border) const
00066 {
00067 return Min(fMinV, scale) - border;
00068 }
00069
00070
00071 float Anp::DrawSpan::GetMaxV(const float scale, const float border) const
00072 {
00073 return Max(fMaxV, scale) + border;
00074 }
00075
00076
00077 float Anp::DrawSpan::GetMinZ(const float scale, const float border) const
00078 {
00079 return Min(fMinZ, scale) - border;
00080 }
00081
00082
00083 float Anp::DrawSpan::GetMaxZ(const float scale, const float border) const
00084 {
00085 return Max(fMaxZ, scale) + border;
00086 }
00087
00088
00089 double Anp::DrawSpan::GetMinTime(const double window) const
00090 {
00091 if(window < 0.0)
00092 {
00093 return fMinTime;
00094 }
00095
00096 return fMinTime - window;
00097 }
00098
00099
00100 double Anp::DrawSpan::GetMaxTime(const double window) const
00101 {
00102 if(window < 0.0)
00103 {
00104 return fMaxTime;
00105 }
00106
00107 return fMaxTime + window;
00108 }
00109
00110
00111 float Anp::DrawSpan::Min(const float pos, const float scale) const
00112 {
00113 if(scale < 1.0)
00114 {
00115 return pos;
00116 }
00117
00118 if(pos < 0.0)
00119 {
00120 return pos * scale;
00121 }
00122
00123 return pos / scale;
00124 }
00125
00126
00127 float Anp::DrawSpan::Max(const float pos, const float scale) const
00128 {
00129 if(scale < 1.0)
00130 {
00131 return pos;
00132 }
00133
00134 if(pos < 0.0)
00135 {
00136 return pos / scale;
00137 }
00138
00139 return pos * scale;
00140 }
00141
00142
00143 void Anp::DrawSpan::SetRangeU(TAxis *axis, const float scale, const float border) const
00144 {
00145 Set(axis, GetMinU(scale, border), GetMaxU(scale, border));
00146 }
00147
00148
00149 void Anp::DrawSpan::SetRangeV(TAxis *axis, const float scale, const float border) const
00150 {
00151 Set(axis, GetMinV(scale, border), GetMaxV(scale, border));
00152 }
00153
00154
00155 void Anp::DrawSpan::SetRangeZ(TAxis *axis, const float scale, const float border) const
00156 {
00157 Set(axis, GetMinZ(scale, border), GetMaxZ(scale, border));
00158 }
00159
00160
00161 bool Anp::DrawSpan::InitU() const
00162 {
00163 return fInitU;
00164 }
00165
00166
00167 bool Anp::DrawSpan::InitV() const
00168 {
00169 return fInitV;
00170 }
00171
00172
00173 bool Anp::DrawSpan::InitZ() const
00174 {
00175 return fInitZ;
00176 }
00177
00178
00179 void Anp::DrawSpan::Set(TAxis *axis, float min, float max) const
00180 {
00181 if(!axis)
00182 {
00183 return;
00184 }
00185
00186 const float xmax = axis -> GetXmax();
00187 const float xmin = axis -> GetXmin();
00188
00189 if(min < xmin)
00190 {
00191 min = xmin;
00192 }
00193 if(max > xmax)
00194 {
00195 max = xmax;
00196 }
00197
00198 axis -> SetRangeUser(min, max);
00199 }
00200
00201
00202 void Anp::DrawSpan::FindSpan(const Event &event, const Record &record)
00203 {
00204 Draw::SVec uvec, vvec;
00205
00206 for(Anp::StripIter sit = record.StripBeg(); sit != record.StripEnd(); ++sit)
00207 {
00208 if(!sit -> MatchEvt(event.EventIndex()))
00209 {
00210 continue;
00211 }
00212
00213 if(sit -> GetPlane() % 2 == 1)
00214 {
00215 uvec.push_back(sit);
00216 }
00217 else
00218 {
00219 vvec.push_back(sit);
00220 }
00221 }
00222
00223 FindSpan(uvec, vvec);
00224 }
00225
00226
00227 void Anp::DrawSpan::FindSpan(const Draw::SVec &uvec, const Draw::SVec &vvec)
00228 {
00229 if(!uvec.empty())
00230 {
00231 if(!fInitTime)
00232 {
00233 const Strip &strip = *(*uvec.begin());
00234 fMinTime = strip.Time();
00235 fMaxTime = strip.Time();
00236 fInitTime = true;
00237 }
00238 if(!fInitU)
00239 {
00240 const Strip &strip = *(*uvec.begin());
00241 fMinU = strip.TPos();
00242 fMaxU = strip.TPos();
00243 fInitU = true;
00244 }
00245 if(!fInitZ)
00246 {
00247 const Strip &strip = *(*uvec.begin());
00248 fMinZ = strip.ZPos();
00249 fMaxZ = strip.ZPos();
00250 fInitZ = true;
00251 }
00252
00253 for(Draw::SIter sit = uvec.begin(); sit != uvec.end(); ++sit)
00254 {
00255 const float upos = (*sit) -> TPos();
00256 const float zpos = (*sit) -> ZPos();
00257 const double time = (*sit) -> Time();
00258
00259 if(fMinU > upos)
00260 {
00261 fMinU = upos;
00262 }
00263 if(fMaxU < upos)
00264 {
00265 fMaxU = upos;
00266 }
00267 if(fMinZ > zpos)
00268 {
00269 fMinZ = zpos;
00270 }
00271 if(fMaxZ < zpos)
00272 {
00273 fMaxZ = zpos;
00274 }
00275 if(fMinTime > time)
00276 {
00277 fMinTime = time;
00278 }
00279 if(fMaxTime < time)
00280 {
00281 fMaxTime = time;
00282 }
00283 }
00284 }
00285
00286 if(!vvec.empty())
00287 {
00288 if(!fInitTime)
00289 {
00290 const Strip &strip = *(*vvec.begin());
00291 fMinTime = strip.Time();
00292 fMaxTime = strip.Time();
00293 fInitTime = true;
00294 }
00295 if(!fInitV)
00296 {
00297 const Strip &strip = *(*vvec.begin());
00298 fMinV = strip.TPos();
00299 fMaxV = strip.TPos();
00300 fInitV = true;
00301 }
00302 if(!fInitZ)
00303 {
00304 const Strip &strip = *(*vvec.begin());
00305 fMinZ = strip.ZPos();
00306 fMaxZ = strip.ZPos();
00307 fInitZ = true;
00308 }
00309
00310 for(Draw::SIter sit = vvec.begin(); sit != vvec.end(); ++sit)
00311 {
00312 const float vpos = (*sit) -> TPos();
00313 const float zpos = (*sit) -> ZPos();
00314 const double time = (*sit) -> Time();
00315
00316 if(fMinV > vpos)
00317 {
00318 fMinV = vpos;
00319 }
00320 if(fMaxV < vpos)
00321 {
00322 fMaxV = vpos;
00323 }
00324 if(fMinZ > zpos)
00325 {
00326 fMinZ = zpos;
00327 }
00328 if(fMaxZ < zpos)
00329 {
00330 fMaxZ = zpos;
00331 }
00332 if(fMinTime > time)
00333 {
00334 fMinTime = time;
00335 }
00336 if(fMaxTime < time)
00337 {
00338 fMaxTime = time;
00339 }
00340 }
00341 }
00342 }
00343