00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 #include "Riostream.h"
00013 
00014 #include "TPointsArray3D.h"
00015 #include "TVirtualPad.h"
00016 #include "TView.h"
00017 #include "TClass.h"
00018 #include "TROOT.h"
00019 #include "TMath.h"
00020 
00021 
00022 
00023 
00024 
00025 
00026 
00027 
00028 
00029 
00030 
00031 
00032 
00033 
00034 
00035 
00036 
00037 
00038 
00039 
00040 
00041 
00042 
00043 
00044 
00045 
00046 
00047 
00048 
00049 
00050 
00051 
00052 
00053 
00054 
00055 
00056 
00057 
00058 ClassImp(TPointsArray3D)
00059 
00060 
00061 TPointsArray3D::TPointsArray3D()
00062 {
00063 
00064 
00065 
00066    fN = 0;
00067    fP = 0;
00068    fLastPoint = -1;
00069    fGLList = 0;
00070    fLastPoint = 0;
00071 }
00072 
00073 
00074 
00075 TPointsArray3D::TPointsArray3D(Int_t n, Option_t *option)
00076 {
00077 
00078 
00079 
00080 
00081    fLastPoint = -1;
00082    if (n < 1) fN = 2;  
00083    else fN = n;
00084 
00085    fP = new Float_t[3*fN];
00086    memset(fP,0,3*fN*sizeof(Float_t));
00087    fOption = option;
00088 
00089    fGLList = 0;
00090    fLastPoint = 0;
00091 }
00092 
00093 
00094 TPointsArray3D::TPointsArray3D(Int_t n, Float_t *p, Option_t *option)
00095 {
00096 
00097 
00098 
00099 
00100 
00101    if (n < 1) fN = 2;  
00102    else fN = n;
00103 
00104    fP = new Float_t[3*fN];
00105    if (n > 0) {
00106       memcpy(fP,p,3*fN*sizeof(Float_t));
00107       fLastPoint = fN-1;
00108    } else {
00109       memset(fP,0,3*fN*sizeof(Float_t));
00110       fLastPoint = -1;
00111    }
00112    fOption = option;
00113 
00114    fGLList = 0;
00115    fLastPoint = 0;
00116 }
00117 
00118 
00119 
00120 TPointsArray3D::TPointsArray3D(Int_t n, Float_t *x, Float_t *y, Float_t *z, Option_t *option)
00121 {
00122 
00123 
00124 
00125 
00126 
00127    fLastPoint = -1;
00128    if (n < 1) fN = 2;  
00129    else fN = n;
00130 
00131    fP = new Float_t[3*fN];
00132    Int_t j = 0;
00133    if (n > 0) {
00134       for (Int_t i=0; i<n;i++) {
00135          fP[j++] = x[i];
00136          fP[j++] = y[i];
00137          fP[j++] = z[i];
00138       }
00139       fLastPoint = fN-1;
00140    } else {
00141       memset(fP,0,3*fN*sizeof(Float_t));
00142    }
00143    fOption = option;
00144 
00145    fGLList = 0;
00146    fLastPoint = 0;
00147 }
00148 
00149 
00150 
00151 TPointsArray3D::~TPointsArray3D()
00152 {
00153 
00154 
00155 
00156    if (fP) delete [] fP;
00157 
00158 }
00159 
00160 
00161 
00162 TPointsArray3D::TPointsArray3D(const TPointsArray3D &point) : TPoints3DABC(point),
00163                                                               fN(point.fN),fP(0),fGLList(point.fGLList),fLastPoint(point.fLastPoint)
00164 {
00165    
00166    ((TPointsArray3D&)point).Copy(*this);
00167 }
00168 
00169 
00170 
00171 void TPointsArray3D::Copy(TObject &obj) const
00172 {
00173 
00174 
00175 
00176    TObject::Copy(obj);
00177    ((TPointsArray3D&)obj).fN = fN;
00178    if (((TPointsArray3D&)obj).fP)
00179       delete [] ((TPointsArray3D&)obj).fP;
00180    ((TPointsArray3D&)obj).fP = new Float_t[3*fN];
00181    for (Int_t i=0; i<3*fN;i++)  {((TPointsArray3D&)obj).fP[i] = fP[i];}
00182    ((TPointsArray3D&)obj).fOption = fOption;
00183    ((TPointsArray3D&)obj).fLastPoint = fLastPoint;
00184 }
00185 
00186 
00187 
00188 Int_t TPointsArray3D::DistancetoPrimitive(Int_t px, Int_t py)
00189 {
00190 
00191 
00192 
00193 
00194 
00195 
00196 
00197 
00198 
00199 
00200    const Int_t inaxis = 7;
00201    Float_t dist = 9999;
00202 
00203    Int_t puxmin = gPad->XtoAbsPixel(gPad->GetUxmin());
00204    Int_t puymin = gPad->YtoAbsPixel(gPad->GetUymin());
00205    Int_t puxmax = gPad->XtoAbsPixel(gPad->GetUxmax());
00206    Int_t puymax = gPad->YtoAbsPixel(gPad->GetUymax());
00207 
00208 
00209    if (px < puxmin - inaxis) return Int_t (dist);
00210    if (py > puymin + inaxis) return Int_t (dist);
00211    if (px > puxmax + inaxis) return Int_t (dist);
00212    if (py < puymax - inaxis) return Int_t (dist);
00213 
00214    TView *view = gPad->GetView();
00215    if (!view) return Int_t(dist);
00216    Int_t i;
00217    Float_t dpoint;
00218    Float_t xndc[3];
00219    Int_t x1,y1;
00220    Int_t size = Size();
00221    for (i=0;i<size;i++) {
00222       view->WCtoNDC(&fP[3*i], xndc);
00223       x1     = gPad->XtoAbsPixel(xndc[0]);
00224       y1     = gPad->YtoAbsPixel(xndc[1]);
00225       dpoint = (px-x1)*(px-x1) + (py-y1)*(py-y1);
00226       if (dpoint < dist) dist = dpoint;
00227    }
00228    return Int_t(TMath::Sqrt(dist));
00229 }
00230 
00231 
00232 
00233 void TPointsArray3D::ExecuteEvent(Int_t event, Int_t px, Int_t py)
00234 {
00235 
00236 
00237    if (gPad->GetView())
00238       gPad->GetView()->ExecuteRotateView(event, px, py);
00239 }
00240 
00241 
00242 void TPointsArray3D::ls(Option_t *option) const
00243 {
00244 
00245 
00246 
00247    TROOT::IndentLevel();
00248    cout << IsA()->GetName() << " N=" <<fN<<" Option="<<option<<endl;
00249 
00250 }
00251 
00252 void TPointsArray3D::Print(Option_t *option) const
00253 {
00254 
00255 
00256 
00257    cout <<"   " << IsA()->GetName() <<" Printing N=" <<fN<<" Option="<<option<<endl;
00258 }
00259 
00260 Int_t TPointsArray3D::SetLastPosition(Int_t idx)
00261 {
00262    
00263    fLastPoint = TMath::Min(idx,GetN()-1);
00264    return idx;
00265 }
00266 
00267 
00268 Int_t TPointsArray3D::SetPoint(Int_t n, Float_t x, Float_t y, Float_t z)
00269 {
00270 
00271 
00272 
00273 
00274 
00275 
00276 
00277 
00278    if (n < 0) return n;
00279    if (!fP || n >= fN) {
00280    
00281       Int_t step = TMath::Max(10, fN/4);
00282       Float_t *savepoint = new Float_t [3*(fN+step)];
00283       if (fP && fN){
00284          memcpy(savepoint,fP,3*fN*sizeof(Float_t));
00285          delete [] fP;
00286       }
00287       fP = savepoint;
00288       fN += step;
00289    }
00290    fP[3*n  ] = x;
00291    fP[3*n+1] = y;
00292    fP[3*n+2] = z;
00293    fLastPoint = TMath::Max(fLastPoint,n);
00294    return fLastPoint;
00295 }
00296 
00297 
00298 Int_t TPointsArray3D::SetPoints(Int_t n, Float_t *p, Option_t *option)
00299 {
00300 
00301 
00302 
00303 
00304 
00305    if (n < 0) return n;
00306    fN = n;
00307    if (fP) delete [] fP;
00308    fP = new Float_t[3*fN];
00309    for (Int_t i=0; i<3*fN;i++) {
00310       if (p) fP[i] = p[i];
00311       else   memset(fP,0,3*fN*sizeof(Float_t));
00312    }
00313    fOption = option;
00314    fLastPoint = fN-1;
00315    return fLastPoint;
00316 }
00317 
00318 
00319 void TPointsArray3D::Streamer(TBuffer &b)
00320 {
00321 
00322 
00323    if (b.IsReading()) {
00324       b.ReadVersion();  
00325       TObject::Streamer(b);
00326       b >> fN;
00327       if (fN) {
00328          fP = new Float_t[3*fN];
00329          b.ReadFastArray(fP,3*fN);
00330       }
00331       fOption.Streamer(b);
00332       fLastPoint = fN;
00333    } else {
00334       b.WriteVersion(TPointsArray3D::IsA());
00335       TObject::Streamer(b);
00336       Int_t size = Size();
00337       b << size;
00338       if (size) b.WriteFastArray(fP, 3*size);
00339       fOption.Streamer(b);
00340    }
00341 }