ROOT  6.06/09
Reference Guide
TPointSet3D.cxx
Go to the documentation of this file.
1 // @(#)root/g3d:$Id$
2 // Author: Matevz Tadel 7/4/2006
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2006, Rene Brun and Fons Rademakers. *
6  * All rights reserved. *
7  * *
8  * For the licensing terms see $ROOTSYS/LICENSE. *
9  * For the list of contributors see $ROOTSYS/README/CREDITS. *
10  *************************************************************************/
11 
12 #include "TPointSet3D.h"
13 #include "TClass.h"
14 
15 /** \class TPointSet3D
16 \ingroup g3d
17 
18 TPolyMarker3D using TPointSet3DGL for direct OpenGL rendering.
19 Supports only elementary marker types:
20  - 4, 20, 24 : round points, size in pixels;
21  - 2, 3, 5 : crosses, size in scene units;
22  - 28 : as above, line width 2 pixels;
23  - all other : square points, size in pixels.
24 
25 Marker-size (from TAttMarker) is multiplied by 5!
26 
27 An identification of type TObject* can be assigned to each point
28 via SetPointId() method. Set the fOwnIds flag if the ids are owned
29 by the point-set and should be deleted when pointset is cleared or
30 destructed.
31 
32 Copy-constructor and assignment operator COPIES the ids if the are
33 not owned and CLONES them if they are owned.
34 
35 The ids are not streamed.
36 */
37 
39 
40 ////////////////////////////////////////////////////////////////////////////////
41 /// Copy constructor.
42 
44  TPolyMarker3D(t), TAttBBox(t), fOwnIds(kFALSE), fIds()
45 {
46  CopyIds(t);
47 }
48 
49 ////////////////////////////////////////////////////////////////////////////////
50 /// Destructor.
51 
53 {
54  ClearIds();
55 }
56 
57 ////////////////////////////////////////////////////////////////////////////////
58 /// Copy id objects from point-set 't'.
59 
61 {
62  fOwnIds = t.fOwnIds;
63  fIds.Expand(t.fIds.GetSize());
64  if (fOwnIds) {
65  for (Int_t i=0; i<t.fIds.GetSize(); ++i)
66  fIds.AddAt(t.fIds.At(i)->Clone(), i);
67  } else {
68  for (Int_t i=0; i<t.fIds.GetSize(); ++i)
69  fIds.AddAt(t.fIds.At(i), i);
70  }
71 }
72 
73 ////////////////////////////////////////////////////////////////////////////////
74 /// Assignment operator.
75 
77 {
78  if (this != &t) {
79  ClearIds();
81  CopyIds(t);
82  }
83  return *this;
84 }
85 
86 ////////////////////////////////////////////////////////////////////////////////
87 /// Compute the bounding box of this points set.
88 
90 {
91  if (Size() > 0) {
92  BBoxInit();
93  Int_t n = Size();
94  Float_t* p = fP;
95  for (Int_t i = 0; i < n; ++i, p += 3) {
96  BBoxCheckPoint(p);
97  }
98  } else {
99  BBoxZero();
100  }
101 }
102 ////////////////////////////////////////////////////////////////////////////////
103 /// Set id of last point.
104 /// Use this method if you also use TPolyMarker3D::SetNextPoint().
105 
107 {
108  SetPointId(fLastPoint, id);
109 }
110 
111 ////////////////////////////////////////////////////////////////////////////////
112 /// Set id of point n.
113 
115 {
116  if (n >= fN) return;
117  if (fN > fIds.GetSize())
118  fIds.Expand(fN);
119  fIds.AddAt(id, n);
120 }
121 
122 ////////////////////////////////////////////////////////////////////////////////
123 /// Clears the id-array. If ids are owned the TObjects are deleted.
124 
126 {
127  if (fOwnIds) {
128  for (Int_t i=0; i<fIds.GetSize(); ++i)
129  delete GetPointId(i);
130  }
131  fIds.Expand(0);
132 }
133 
134 ////////////////////////////////////////////////////////////////////////////////
135 /// This virtual method is called from TPointSet3DGL when a point is
136 /// selected.
137 ///
138 /// At this point it just prints out n and id of the point (if it exists).
139 /// To make something useful out of this do:
140 ///
141 /// 1. subclass and re-implement this method;
142 /// 2. extend this class to include TExec or some other kind of callback.
143 
145 {
146  TObject* id = GetPointId(n);
147  printf("TPointSet3D::PointSelected n=%d, id=(%s*)0x%lx\n",
148  n, id ? id->IsA()->GetName() : "void", (ULong_t)id);
149  if (id)
150  id->Print();
151 }
152 
153 ////////////////////////////////////////////////////////////////////////////////
154 /// Stream an object of class TPointSet3D.
155 
156 void TPointSet3D::Streamer(TBuffer &R__b)
157 {
158  if (R__b.IsReading()) {
159  R__b.ReadClassBuffer(TPointSet3D::Class(), this);
160  if (fOwnIds) {
161  Int_t n;
162  R__b >> n;
163  for (Int_t i=0; i<n; ++i) {
165  if (gDebug > 0) { printf("Read[%2d]: ", i); o->Print(); }
166  }
167  }
168  } else {
169  R__b.WriteClassBuffer(TPointSet3D::Class(), this);
170  if (fOwnIds) {
171  R__b << fIds.GetEntries();
172  TObject* o;
173  TIter next(&fIds);
174  while ((o = next())) {
175  if (gDebug > 0) { printf("Writing: "); o->Print(); }
176  R__b.WriteObjectAny(o, TObject::Class());
177  }
178  }
179  }
180 }
virtual Int_t WriteClassBuffer(const TClass *cl, void *pointer)=0
Bool_t IsReading() const
Definition: TBuffer.h:81
ClassImp(TSeqCollection) Int_t TSeqCollection TIter next(this)
Return index of object in collection.
float Float_t
Definition: RtypesCore.h:53
virtual void Expand(Int_t newSize)
Expand or shrink the array to newSize elements.
Definition: TRefArray.cxx:473
TObject * GetPointId(Int_t n) const
Definition: TPointSet3D.h:52
virtual Int_t WriteObjectAny(const void *obj, const TClass *ptrClass)=0
Bool_t fOwnIds
Definition: TPointSet3D.h:28
virtual Int_t Size() const
Definition: TPolyMarker3D.h:81
Buffer base class used for serializing objects.
Definition: TBuffer.h:40
void ClearIds()
Clears the id-array. If ids are owned the TObjects are deleted.
int Int_t
Definition: RtypesCore.h:41
const Bool_t kFALSE
Definition: Rtypes.h:92
TPolyMarker3D & operator=(const TPolyMarker3D &)
assignment operator
Int_t GetEntries() const
Return the number of objects in array (i.e.
Definition: TRefArray.cxx:588
virtual TObject * Clone(const char *newname="") const
Make a clone of an object using the Streamer facility.
Definition: TObject.cxx:203
void BBoxCheckPoint(Float_t x, Float_t y, Float_t z)
Definition: TAttBBox.h:60
virtual ~TPointSet3D()
Destructor.
Definition: TPointSet3D.cxx:52
TObject * At(Int_t idx) const
Definition: TRefArray.h:184
void Class()
Definition: Class.C:29
void SetPointId(TObject *id)
Set id of last point.
virtual void Print(Option_t *option="") const
This method must be overridden when a class wants to print itself.
Definition: TObject.cxx:594
TPointSet3D & operator=(const TPointSet3D &t)
Assignment operator.
Definition: TPointSet3D.cxx:76
virtual void PointSelected(Int_t n)
This virtual method is called from TPointSet3DGL when a point is selected.
virtual void AddAt(TObject *obj, Int_t idx)
Add object at position ids.
Definition: TRefArray.cxx:358
void BBoxZero(Float_t epsilon=0, Float_t x=0, Float_t y=0, Float_t z=0)
Create cube of volume (2*epsilon)^3 at (x,y,z).
Definition: TAttBBox.cxx:39
virtual void ComputeBBox()
Compute the bounding box of this points set.
Definition: TPointSet3D.cxx:89
void CopyIds(const TPointSet3D &t)
Copy id objects from point-set 't'.
Definition: TPointSet3D.cxx:60
virtual Int_t ReadClassBuffer(const TClass *cl, void *pointer, const TClass *onfile_class=0)=0
virtual Int_t GetSize() const
Definition: TCollection.h:95
virtual const char * GetName() const
Returns name of object.
Definition: TObject.cxx:415
ClassImp(TMCParticle) void TMCParticle printf(": p=(%7.3f,%7.3f,%9.3f) ;", fPx, fPy, fPz)
unsigned long ULong_t
Definition: RtypesCore.h:51
ClassImp(TPointSet3D)
virtual void * ReadObjectAny(const TClass *cast)=0
Mother of all ROOT objects.
Definition: TObject.h:58
TRefArray fIds
Definition: TPointSet3D.h:29
A 3D polymarker.
Definition: TPolyMarker3D.h:40
Helper for management of bounding-box information.
Definition: TAttBBox.h:19
R__EXTERN Int_t gDebug
Definition: Rtypes.h:128
TPolyMarker3D using TPointSet3DGL for direct OpenGL rendering.
Definition: TPointSet3D.h:25
Float_t * fP
Definition: TPolyMarker3D.h:44
const Int_t n
Definition: legend1.C:16
void BBoxInit(Float_t infinity=1e6)
Dynamic Float_t[6] X(min,max), Y(min,max), Z(min,max)