TPointSet3D.cxx

Go to the documentation of this file.
00001 // @(#)root/g3d:$Id: TPointSet3D.cxx 33864 2010-06-14 09:47:19Z matevz $
00002 // Author: Matevz Tadel  7/4/2006
00003 
00004 /*************************************************************************
00005  * Copyright (C) 1995-2006, Rene Brun and Fons Rademakers.               *
00006  * All rights reserved.                                                  *
00007  *                                                                       *
00008  * For the licensing terms see $ROOTSYS/LICENSE.                         *
00009  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
00010  *************************************************************************/
00011 
00012 
00013 #include "TPointSet3D.h"
00014 #include "TClass.h"
00015 
00016 //______________________________________________________________________
00017 //
00018 // TPolyMarker3D using TPointSet3DGL for direct OpenGL rendering.
00019 // Supports only elementary marker types:
00020 // 4, 20, 24 : round points, size in pixels;
00021 //   2, 3, 5 : crosses, size in scene units;
00022 //        28 : as above, line width 2 pixels;
00023 // all other : square points, size in pixels.
00024 //
00025 // Marker-size (from TAttMarker) is multiplied by 5!
00026 //
00027 // An identification of type TObject* can be assigned to each point
00028 // via SetPointId() method. Set the fOwnIds flag if the ids are owned
00029 // by the point-set and should be deleted when pointset is cleared or
00030 // destructed.
00031 //
00032 // Copy-constructor and assignment operator COPIES the ids if the are
00033 // not owned and CLONES them if they are owned.
00034 //
00035 // The ids are not streamed. 
00036 
00037 ClassImp(TPointSet3D);
00038 
00039 //______________________________________________________________________________
00040 TPointSet3D::TPointSet3D(const TPointSet3D &t) :
00041    TPolyMarker3D(t), TAttBBox(t), fOwnIds(kFALSE), fIds()
00042 {
00043    // Copy constructor.
00044 
00045    CopyIds(t);
00046 }
00047 
00048 //______________________________________________________________________________
00049 TPointSet3D::~TPointSet3D()
00050 {
00051    // Destructor.
00052 
00053    ClearIds();
00054 }
00055 
00056 //______________________________________________________________________________
00057 void TPointSet3D::CopyIds(const TPointSet3D& t)
00058 {
00059    // Copy id objects from point-set 't'.
00060 
00061    fOwnIds = t.fOwnIds;
00062    fIds.Expand(t.fIds.GetSize());
00063    if (fOwnIds) {
00064       for (Int_t i=0; i<t.fIds.GetSize(); ++i)
00065          fIds.AddAt(t.fIds.At(i)->Clone(), i);
00066    } else {
00067       for (Int_t i=0; i<t.fIds.GetSize(); ++i)
00068          fIds.AddAt(t.fIds.At(i), i);
00069    }
00070 }
00071 
00072 //______________________________________________________________________________
00073 TPointSet3D& TPointSet3D::operator=(const TPointSet3D& t)
00074 {
00075    // Assignement operator.
00076 
00077    if (this != &t) {
00078       ClearIds();
00079       TPolyMarker3D::operator=(t);
00080       CopyIds(t);
00081    }
00082    return *this;
00083 }
00084 
00085 //______________________________________________________________________________
00086 void TPointSet3D::ComputeBBox()
00087 {
00088    // Compute the bounding box of this points set.
00089 
00090    if (Size() > 0) {
00091       BBoxInit();
00092       Int_t    n = Size();
00093       Float_t* p = fP;
00094       for (Int_t i = 0; i < n; ++i, p += 3) {
00095          BBoxCheckPoint(p);
00096       }
00097    } else {
00098       BBoxZero();
00099    }
00100 }
00101 //______________________________________________________________________________
00102 void TPointSet3D::SetPointId(TObject* id)
00103 {
00104    // Set id of last point.
00105    // Use this method if you also use TPolyMarker3D::SetNextPoint().
00106 
00107    SetPointId(fLastPoint, id);
00108 }
00109 
00110 //______________________________________________________________________________
00111 void TPointSet3D::SetPointId(Int_t n, TObject* id)
00112 {
00113    // Set id of point n.
00114 
00115    if (n >= fN) return;
00116    if (fN > fIds.GetSize())
00117       fIds.Expand(fN);
00118    fIds.AddAt(id, n);
00119 }
00120 
00121 //______________________________________________________________________________
00122 void TPointSet3D::ClearIds()
00123 {
00124    // Clears the id-array. If ids are owned the TObjects are deleted.
00125 
00126    if (fOwnIds) {
00127       for (Int_t i=0; i<fIds.GetSize(); ++i)
00128          delete GetPointId(i);
00129    }
00130    fIds.Expand(0);
00131 }
00132 
00133 //______________________________________________________________________________
00134 void TPointSet3D::PointSelected(Int_t n)
00135 {
00136    // This virtual method is called from TPointSet3DGL when a point is
00137    // selected.
00138    // At this point it just prints out n and id of the point (if it exists).
00139    // To make something useful out of this do:
00140    //  a) subclass and re-implement this method;
00141    //  b) extend this class to include TExec or some other kind of callback.
00142 
00143    TObject* id = GetPointId(n);
00144    printf("TPointSet3D::PointSelected n=%d, id=(%s*)0x%lx\n",
00145           n, id ? id->IsA()->GetName() : "void", (ULong_t)id);
00146    if (id)
00147       id->Print();
00148 }
00149 
00150 //______________________________________________________________________________
00151 void TPointSet3D::Streamer(TBuffer &R__b)
00152 {
00153    // Stream an object of class TPointSet3D.
00154 
00155    if (R__b.IsReading()) {
00156       R__b.ReadClassBuffer(TPointSet3D::Class(), this);
00157       if (fOwnIds) {
00158          Int_t n;
00159          R__b >> n;
00160          for (Int_t i=0; i<n; ++i) {
00161             TObject* o = (TObject*) R__b.ReadObjectAny(TObject::Class());
00162             if (gDebug > 0) printf("Read[%2d]: ", i); o->Print();
00163          }
00164       }
00165    } else {
00166       R__b.WriteClassBuffer(TPointSet3D::Class(), this);
00167       if (fOwnIds) {
00168          R__b << fIds.GetEntries();
00169          TObject* o;
00170          TIter next(&fIds);
00171          while ((o = next())) {
00172             if (gDebug > 0) printf("Writing: "); o->Print();
00173             R__b.WriteObjectAny(o, TObject::Class());
00174          }
00175       }
00176    }
00177 }

Generated on Tue Jul 5 14:16:41 2011 for ROOT_528-00b_version by  doxygen 1.5.1